diff --git a/firmware/applications/funk.c b/firmware/applications/funk.c index cbdfa9d..7195658 100644 --- a/firmware/applications/funk.c +++ b/firmware/applications/funk.c @@ -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; diff --git a/firmware/funk/nrf24l01p.c b/firmware/funk/nrf24l01p.c index 81642d6..4f657f2 100644 --- a/firmware/funk/nrf24l01p.c +++ b/firmware/funk/nrf24l01p.c @@ -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); }; diff --git a/firmware/funk/nrf24l01p.h b/firmware/funk/nrf24l01p.h index d811bbd..9aaae96 100644 --- a/firmware/funk/nrf24l01p.h +++ b/firmware/funk/nrf24l01p.h @@ -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