Move crc handling to send function. Also: change chip-crc to openbeacon compatible values
This commit is contained in:
parent
1e7e82b2c5
commit
8987b5c15c
|
@ -90,11 +90,8 @@ void f_send(void){
|
||||||
|
|
||||||
buf[12]=0xff; // salt (0xffff always?)
|
buf[12]=0xff; // salt (0xffff always?)
|
||||||
buf[13]=0xff;
|
buf[13]=0xff;
|
||||||
crc=crc16(buf,14);
|
|
||||||
buf[14]=(crc >>8) & 0xff; // CRC
|
|
||||||
buf[15]=crc & 0xff; // CRC
|
|
||||||
|
|
||||||
status=nrf_snd_pkt_crc(16,buf);
|
status=nrf_snd_pkt_crc(14,buf);
|
||||||
|
|
||||||
dx=DoString(0,dy,"St:"); DoIntX(dx,dy,status); dy+=8;
|
dx=DoString(0,dy,"St:"); DoIntX(dx,dy,status); dy+=8;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ void nrf_init() {
|
||||||
nrf_write_reg(R_CONFIG,
|
nrf_write_reg(R_CONFIG,
|
||||||
R_CONFIG_PRIM_RX| // Receive mode
|
R_CONFIG_PRIM_RX| // Receive mode
|
||||||
R_CONFIG_PWR_UP| // Power on
|
R_CONFIG_PWR_UP| // Power on
|
||||||
R_CONFIG_CRCO // 2-byte CRC
|
R_CONFIG_EN_CRC // CRC on, single byte
|
||||||
);
|
);
|
||||||
|
|
||||||
nrf_write_reg(R_EN_AA, 0); // Disable Enhanced ShockBurst;
|
nrf_write_reg(R_EN_AA, 0); // Disable Enhanced ShockBurst;
|
||||||
|
@ -115,7 +115,7 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt){
|
||||||
nrf_write_reg(R_CONFIG,
|
nrf_write_reg(R_CONFIG,
|
||||||
R_CONFIG_PRIM_RX| // Receive mode
|
R_CONFIG_PRIM_RX| // Receive mode
|
||||||
R_CONFIG_PWR_UP| // Power on
|
R_CONFIG_PWR_UP| // Power on
|
||||||
R_CONFIG_CRCO // 2-byte CRC
|
R_CONFIG_EN_CRC // CRC on, single byte
|
||||||
);
|
);
|
||||||
|
|
||||||
nrf_cmd(C_FLUSH_RX);
|
nrf_cmd(C_FLUSH_RX);
|
||||||
|
@ -160,18 +160,27 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt){
|
||||||
char nrf_snd_pkt_crc(int size, uint8_t * pkt){
|
char nrf_snd_pkt_crc(int size, uint8_t * pkt){
|
||||||
char status;
|
char status;
|
||||||
|
|
||||||
|
if(size > MAX_PKT)
|
||||||
|
size=MAX_PKT;
|
||||||
|
|
||||||
nrf_write_reg(R_CONFIG,
|
nrf_write_reg(R_CONFIG,
|
||||||
R_CONFIG_PWR_UP| // Power on
|
R_CONFIG_PWR_UP| // Power on
|
||||||
R_CONFIG_EN_CRC // CRC on, single byte
|
R_CONFIG_EN_CRC // CRC on, single byte
|
||||||
);
|
);
|
||||||
|
|
||||||
nrf_write_long(C_W_TX_PAYLOAD,size,pkt);
|
// nrf_write_long(C_W_TX_PAYLOAD,size,pkt);
|
||||||
|
uint16_t crc=crc16(pkt,size);
|
||||||
|
CS_LOW();
|
||||||
|
xmit_spi(C_W_TX_PAYLOAD);
|
||||||
|
sspSend(0,pkt,size);
|
||||||
|
xmit_spi((crc >>8) & 0xff);
|
||||||
|
xmit_spi(crc & 0xff);
|
||||||
|
CS_HIGH();
|
||||||
|
|
||||||
|
|
||||||
CE_HIGH();
|
CE_HIGH();
|
||||||
delayms(10); // Send it. (only needs >10ys, i think)
|
delayms(1); // Send it. (only needs >10ys, i think)
|
||||||
CE_LOW();
|
CE_LOW();
|
||||||
|
|
||||||
CS_LOW(); status=C_NOP; sspSendReceive(0, &status, 1); CS_HIGH();
|
return nrf_cmd_status(C_NOP);
|
||||||
|
|
||||||
return status;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef _NRF24L01P_H
|
#ifndef _NRF24L01P_H
|
||||||
#define _NRF24L01P_H 1
|
#define _NRF24L01P_H 1
|
||||||
|
|
||||||
|
#define MAX_PKT (32-2) // 2 bytes are our CRC
|
||||||
|
|
||||||
// SPI commands
|
// SPI commands
|
||||||
#define C_R_REGISTER 0x00
|
#define C_R_REGISTER 0x00
|
||||||
#define C_W_REGISTER 0x20
|
#define C_W_REGISTER 0x20
|
||||||
|
|
Loading…
Reference in New Issue