- // see if a CRC OK pkt has been arrived
- if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
-+ while((rxfifo_cnt = cc1100_readReg(CC1100_RXBYTES)) != 0x00) {
-+ if (rxfifo_cnt & 0x80) // Overflow
-+ break;
-
-- enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
-+ enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
-
-- if (enc[0]>=MAX_ASKSIN_MSG)
-- enc[0] = MAX_ASKSIN_MSG-1;
--
-- CC1100_ASSERT;
-- cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
--
-- for (uint8_t i=0; i<enc[0]; i++) {
-- enc[i+1] = cc1100_sendbyte( 0 );
-- }
--
-- rssi = cc1100_sendbyte( 0 );
--
-- CC1100_DEASSERT;
-+ if (enc[0]>=MAX_ASKSIN_MSG)
-+ enc[0] = MAX_ASKSIN_MSG-1;
-+
-+ CC1100_ASSERT;
-+ cc1100_sendbyte( CC1100_READ_BURST | CC1100_RXFIFO );
-+
-+ for (uint8_t i=0; i<enc[0]; i++) {
-+ enc[i+1] = cc1100_sendbyte( 0 );
-+ }
-+
-+ rssi = cc1100_sendbyte( 0 );
-+ /* LQI = */ cc1100_sendbyte( 0 );
+- // see if a CRC OK pkt has been arrived
+- if (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
++ // see if there is data to be read
++ while (bit_is_set( CC1100_IN_PORT, CC1100_IN_PIN )) {
++ rxfifo_cnt = read_cc1100_rxbytes();
++
++ if (rxfifo_cnt & 0x80) // Overflow
++ break;
++
++ rxfifo_cnt &= 0x7f;
++
++ // We must not read the last byte from the RX fifo while RX is in progress (Errata 1)
++ while ((rxfifo_cnt < 2) && (cc1100_readReg(CC1100_PKTSTATUS) & (1 << 3))) {
++ my_delay_ms(1);
++ rxfifo_cnt = read_cc1100_rxbytes() & 0x7f;
++ }
++
+ enc[0] = cc1100_readReg( CC1100_RXFIFO ) & 0x7f; // read len
++ rxfifo_cnt--;