Hi!
I have a function called send_network_packet which takes a Serial object, a source address, a destination address, packet data and length, like so:
void send_network_packet(Serial s, char *src, char *dst, char *pkt, uint8_t len) {
int i;
while (!s.writeable()); s.putc(1);
for (i = 0; i < 8; i++) { while (!s.writeable()); s.putc(src[i]); }
for (i = 0; i < 8; i++) { while (!s.writeable()); s.putc(dst[i]); }
while (!s.writeable()); s.putc(len);
for (i = 0; i < len; i++) { while (!s.writeable()); s.putc(pkt[i]); }
}
Don't mind all the writeable() checks, they're there for making sure that nothing is wrong during debugging.
Now, I call this function twice in a row:
send_network_packet(serial[i], ADDR_LOCAL, ADDR_BROADCAST, "OHAITHAR", 8);
send_network_packet(serial[i], ADDR_LOCAL, ADDR_BROADCAST, "OHAITHAR", 8);
I call it with the same data both times. Before I make these calls however I send a bunch of null-bytes.
The problem is that the second message is never sent, and later on in the code I have while(serial[i].readable()) { ... }.
When I receive a character from the PC, readable() will constantly return true, hanging in an infinite loop but it can't actually read or send anything. Any putc()-calls just fails.
Now, if I don't call send_network_packet at all, I can receive characters just fine.
I was also confused as to why the second send_network_packet call fails to send even a single character (but it runs through the code past all writeable() checks). So I changed the function to send everything twice:
void send_network_packet(Serial s, char *src, char *dst, char *pkt, uint8_t len) {
int i;
while (!s.writeable()); s.putc(1);
for (i = 0; i < 8; i++) { while (!s.writeable()); s.putc(src[i]); }
for (i = 0; i < 8; i++) { while (!s.writeable()); s.putc(dst[i]); }
while (!s.writeable()); s.putc(len);
for (i = 0; i < len; i++) { while (!s.writeable()); s.putc(pkt[i]); }
while (!s.writeable()); s.putc(1);
for (i = 0; i < 8; i++) { while (!s.writeable()); s.putc(src[i]); }
for (i = 0; i < 8; i++) { while (!s.writeable()); s.putc(dst[i]); }
while (!s.writeable()); s.putc(len);
for (i = 0; i < len; i++) { while (!s.writeable()); s.putc(pkt[i]); }
}
And it sends it twice! The only difference is that this doesn't return from the function before getting called again.
So, apparently, when this function returns, the UART dies in some funny way.
The serial-array is defined as follows:
Serial serial[4] = { Serial(USBTX, USBRX), Serial(p9, p10), Serial(p13, p14), Serial(p28, p27) };
Any ideas?
Hi!
I have a function called send_network_packet which takes a Serial object, a source address, a destination address, packet data and length, like so:
Don't mind all the writeable() checks, they're there for making sure that nothing is wrong during debugging. Now, I call this function twice in a row:
I call it with the same data both times. Before I make these calls however I send a bunch of null-bytes. The problem is that the second message is never sent, and later on in the code I have while(serial[i].readable()) { ... }. When I receive a character from the PC, readable() will constantly return true, hanging in an infinite loop but it can't actually read or send anything. Any putc()-calls just fails.
Now, if I don't call send_network_packet at all, I can receive characters just fine.
I was also confused as to why the second send_network_packet call fails to send even a single character (but it runs through the code past all writeable() checks). So I changed the function to send everything twice:
And it sends it twice! The only difference is that this doesn't return from the function before getting called again. So, apparently, when this function returns, the UART dies in some funny way.
The serial-array is defined as follows:
Any ideas?