uint8_t rfm70ReceivePayload() { uint8_t len; uint8_t status; uint8_t fifo_status; uint8_t rx_buf[32]; bool msg_received = false; fifo_status = rfm70ReadRegValue(RFM70_REG_FIFO_STATUS); status = rfm70ReadRegValue(RFM70_REG_STATUS); // check if receive data ready (RX_DR) interrupt if (status & RFM70_IRQ_STATUS_RX_DR) { msg_received = true; do { // read length of playload packet len = rfm70ReadRegValue(RFM70_CMD_RX_PL_WID); if (len >= 5 && len <= 32) // 32 = max packet length { // read data from FIFO Buffer rfm70ReadRegPgmBuf(RFM70_CMD_RD_RX_PLOAD, rx_buf, len); // Send message with ack payload of the beacon message // if receiver allows and button is pressed if (stateChanged) { stateChanged = false; rfm70SendPayload(buf, 32, -1, 1); } } else { // flush RX FIFO rfm70WriteRegPgmBuf((uint8_t *)RFM70_CMD_FLUSH_RX, sizeof(RFM70_CMD_FLUSH_RX)); } fifo_status = rfm70ReadRegValue(RFM70_REG_FIFO_STATUS); } while ((fifo_status & RFM70_FIFO_STATUS_RX_EMPTY) == 0); } rfm70WriteRegValue(RFM70_CMD_WRITE_REG | RFM70_REG_STATUS, status); return msg_received; }
uint8_t rfm70ReceivePayload(uint8_t *payload) { uint8_t len; uint8_t status; //uint8_t detect; uint8_t fifo_status; uint8_t rx_buf[32]; status = rfm70ReadRegValue(RFM70_REG_STATUS); /* detect = rfm70ReadRegValue(RFM70_REG_CD); // Read value of Carrier Detection register if (fifo_status & RFM70_FIFO_STATUS_RX_FULL) { return false; } if ((detect & RFM70_CARRIER_DETECTION) == 0x01) // Confirm that the CD bit is set high/low { cbi(PORTC, LED_YELLOW); lcd_goto(1,0); lcd_writeText("CD found ", 16); } else { sbi(PORTC, LED_YELLOW); lcd_goto(1,0); lcd_writeText("CD not found ", 16); } */ //char charValue [6] = " "; // check if receive data ready (RX_DR) interrupt if (status & RFM70_IRQ_STATUS_RX_DR) { do { // read length of playload packet len = rfm70ReadRegValue(RFM70_CMD_RX_PL_WID); if (len <= 32) // 32 = max packet length { // read data from FIFO Buffer rfm70ReadRegPgmBuf(RFM70_CMD_RD_RX_PLOAD, rx_buf, len); sbi(PORTD, LED_RED); _delay_ms(100); cbi(PORTD, LED_RED); nextDigit = &valueBuffer[sizeof(valueBuffer)]; *--nextDigit = 0xff; /* terminate with 0xff */ *--nextDigit = 0; *--nextDigit = KEY_RETURN; *--nextDigit = (rx_buf[0] & 0xf) + 4; /*if(rx_buf[0]&1) { *--nextDigit = KEY_1; } else { *--nextDigit = KEY_0; } if(rx_buf[0]&2) { *--nextDigit = KEY_1; } else { *--nextDigit = KEY_0; } if(rx_buf[0]&4) { *--nextDigit = KEY_1; } else { *--nextDigit = KEY_0; } if(rx_buf[0]&8) { *--nextDigit = KEY_1; } else { *--nextDigit = KEY_0; }*/ //itoa(len, charValue, 16); //lcd_clear(); //lcd_goto(1,0); //lcd_writeText(charValue, 2); //itoa(rx_buf[0], charValue, 16); //lcd_goto(1,3); //lcd_writeText(charValue, 2); //itoa(rx_buf[1], charValue, 16); //lcd_goto(1,6); //lcd_writeText(charValue, 2); //itoa(rx_buf[2], charValue, 16); //lcd_goto(1,9); //lcd_writeText(charValue, 2); } else { // flush RX FIFO rfm70WriteRegPgmBuf((uint8_t *)RFM70_CMD_FLUSH_RX, sizeof(RFM70_CMD_FLUSH_RX)); } fifo_status = rfm70ReadRegValue(RFM70_REG_FIFO_STATUS); } while ((fifo_status & RFM70_FIFO_STATUS_RX_EMPTY) == 0); if ((rx_buf[0] == 0xAA) && (rx_buf[1] == 0x80)) { //sbi(PORTD, LED_RED); _delay_ms(100); //cbi(PORTD, LED_RED); rfm70SetModeRX(); } } rfm70WriteRegValue(RFM70_CMD_WRITE_REG | RFM70_REG_STATUS, status); return 0; }