Move crc handling to send function. Also: change chip-crc to openbeacon compatible values

This commit is contained in:
Stefan `Sec` Zehl 2011-07-10 02:19:10 +02:00
parent 1e7e82b2c5
commit 8987b5c15c
3 changed files with 19 additions and 11 deletions

View File

@ -90,11 +90,8 @@ void f_send(void){
buf[12]=0xff; // salt (0xffff always?)
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;

View File

@ -80,7 +80,7 @@ void nrf_init() {
nrf_write_reg(R_CONFIG,
R_CONFIG_PRIM_RX| // Receive mode
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;
@ -115,7 +115,7 @@ int nrf_rcv_pkt_time(int maxtime, int maxsize, uint8_t * pkt){
nrf_write_reg(R_CONFIG,
R_CONFIG_PRIM_RX| // Receive mode
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);
@ -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 status;
if(size > MAX_PKT)
size=MAX_PKT;
nrf_write_reg(R_CONFIG,
R_CONFIG_PWR_UP| // Power on
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();
delayms(10); // Send it. (only needs >10ys, i think)
delayms(1); // Send it. (only needs >10ys, i think)
CE_LOW();
CS_LOW(); status=C_NOP; sspSendReceive(0, &status, 1); CS_HIGH();
return status;
return nrf_cmd_status(C_NOP);
};

View File

@ -1,6 +1,8 @@
#ifndef _NRF24L01P_H
#define _NRF24L01P_H 1
#define MAX_PKT (32-2) // 2 bytes are our CRC
// SPI commands
#define C_R_REGISTER 0x00
#define C_W_REGISTER 0x20