Hard to explain in subject line.
Got a mega328p communicating wirelessly with a 1284 using two nrf24L01+'s.
I need to be able to send arrays from the 328 to the 1284. When powered up, the 328p tries to send an arbitrary array of size 2 holding 0.123, 0.456 (sends everything always as a character array).
The user clicks a button 7 times which stores 6 timings (the time between button clicks) in an array and then that is sent to the 1284.
In terms of transmission everything works fine, however it always sends the LAST array, when the current array should be sent.
For instance, on power on, the terminal looks like this:
Hello NRF24L01 receive ascii text ATmega1284
"size:23" repeats:
Then I click the button 7 times, and I get this:
0.12300
0.45600"size:67" repeats:
click the button another 7 times and...
0.42500
0.88000
1.34700
1.77300
2.29100
2.75800"size:67" repeats:
i.e what is being displayed is an array behind...make sense?
The code that is receiving a block:
signed int rx_block(void *buf, unsigned int max) { unsigned int repeats = 0, cnt = 0; unsigned char *p = (unsigned char *) buf; unsigned char seq = 0; do { nrf24l01_read_rx_payload((unsigned char *) &packet, 32); //received packet over RF while (!(nrf24l01_irq_pin_active() && (nrf24l01_irq_rx_dr_active()))); if (packet.siz == 0) { // do a sync p = (unsigned char *) buf; uart0_printf("\"% s\" repeats:% u\r\n", packet.data, repeats); max = atoi((char*)&packet.data[5]); //read sizeof block seq = 1; //start packet cnt = 0; //reset counter } else if (packet.seq == seq) { // expected new packet seq++; memcpy(p, packet.data, packet.siz); p += packet.siz; cnt += packet.siz; } else repeats++; // repeated packet while (nrf24l01_irq_pin_active()) //flush any pending interrupts in the 24L01 nrf24l01_irq_clear_all(); if (repeats >= 100) return -1; } while (cnt < max); return repeats; }
the loop in main that is waiting for the block:
while (1) { rx_block(recbuf, 256); uart0_printf("% s\r\n", recbuf); ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed }
Finally this method is called when an array has been populated. It is passed a pointer to the beginning of the array and the size of the array:
void send(float * array, int size) { unsigned int missed = 0, number = 0, i; int ret; char buf[30]; //for building test data inpbuf[0] = '\0'; for (uint8_t i = 0; i < size; i++) { dtostrf(array[i], 10, 5, buf); strcat(inpbuf, buf); strcat(inpbuf, "\n"); } uart0_printf("inpbuf:% s", inpbuf); ret = tx_block(inpbuf, strlen(inpbuf)+1); // want the NULL too DelayMS(1000); if (ret >= 0) missed += ret; else { uart0_printf("packet:% u [missed packets:% u]\r\n", number, missed); } ToggleLED(); //toggle the on-board LED as visual indication that the loop has completed }
P.S
uart0_printf("inpbuf:% s", inpbuf);
displays what I expect to see, and I cant connect both to the terminal at the same time.
If anyone has any ideas about this would greatly appreciate the help.