Serrial communication massive data loss
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Serrial communication massive data loss
You should examine the Serial driver flags, are you getting errors? if so it could be the clock not accurate enough.
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: Serrial communication massive data loss
Ouch. SD_OVERRUN_ERROR all the way from the start of the data, the 2nd byte... does that mean I shall just go and cry in the corner, then put external 4/8mhz crystal?
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Serrial communication massive data loss
You still have the option to use the UART driver, it is possible it can handle it.
About the clock, why not HSI? you can divide it by two or three using the AHB prescaler if you don't want to go up to 16MHz.
Anyway, I can try to rewrite that ISR in a more efficient way using that loop I mentioned.
Giovanni
About the clock, why not HSI? you can divide it by two or three using the AHB prescaler if you don't want to go up to 16MHz.
Anyway, I can try to rewrite that ISR in a more efficient way using that loop I mentioned.
Giovanni
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: Serrial communication massive data loss
Yeah def will go try to UART, tried the HSI on 8mhz - works, went to 4mhz and got SD_OVERRUN_ERROR and SD_BREAK_DETECTED right away. The serial port just dislikes 4mhz and thats it 
And I'm all up for optimizations, serial driver looks way better to a higher level developers like me, there is quite some time before I get to the moment to try to squeeze every uA out of the board, I got the hardware a week ago, and it is still incomplete, so will be happy to test any optimized version along the way
Time for me to hit the sack, gn
And I'm all up for optimizations, serial driver looks way better to a higher level developers like me, there is quite some time before I get to the moment to try to squeeze every uA out of the board, I got the hardware a week ago, and it is still incomplete, so will be happy to test any optimized version along the way
Time for me to hit the sack, gn
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Serrial communication massive data loss
I suggest to try 16/3 too and hold on that solution, I want to optimize that handler now and see how much it can improve with that solution.
Currently it goes out of the ISR after one byte received and, while this is the safest way, it is not optimal. Matter for the next weekend
Giovanni
Currently it goes out of the ISR after one byte received and, while this is the safest way, it is not optimal. Matter for the next weekend
Giovanni
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: Serrial communication massive data loss
Thanks a lot Giovanni, looking forward to it and my first working device somewhere along the way 
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Serrial communication massive data loss
Do you mind testing this code?
Just replace the current function with this one and see if you notice improvements.
Giovanni
Code: Select all
static void serve_interrupt(SerialDriver *sdp) {
USART_TypeDef *u = sdp->usart;
uint16_t cr1 = u->CR1;
uint16_t sr, dr;
/* RX-related sources have priority.*/
while (TRUE) {
sr = u->SR; /* SR reset step 1.*/
dr = u->DR; /* SR reset step 2.*/
if ((sr & (USART_SR_RXNE | USART_SR_ORE | USART_SR_NE |
USART_SR_FE | USART_SR_PE)) == 0)
break;
/* Error condition detection.*/
if (sr & (USART_SR_ORE | USART_SR_NE | USART_SR_FE | USART_SR_PE))
set_error(sdp, sr);
/* Data available.*/
if (sr & USART_SR_RXNE) {
chSysLockFromIsr();
sdIncomingDataI(sdp, (uint8_t)dr);
chSysUnlockFromIsr();
}
}
/* Special case, LIN break detection.*/
if (sr & USART_SR_LBD) {
chSysLockFromIsr();
chIOAddFlagsI(sdp, SD_BREAK_DETECTED);
chSysUnlockFromIsr();
u->SR = ~USART_SR_LBD;
}
/* Transmission buffer empty.*/
if ((cr1 & USART_CR1_TXEIE) && (sr & USART_SR_TXE)) {
msg_t b;
chSysLockFromIsr();
b = chOQGetI(&sdp->oqueue);
if (b < Q_OK) {
chIOAddFlagsI(sdp, IO_OUTPUT_EMPTY);
u->CR1 = (cr1 & ~USART_CR1_TXEIE) | USART_CR1_TCIE;
}
else
u->DR = b;
chSysUnlockFromIsr();
}
/* Physical transmission end.*/
if (sr & USART_SR_TC) {
chSysLockFromIsr();
chIOAddFlagsI(sdp, IO_TRANSMISSION_END);
chSysUnlockFromIsr();
u->CR1 = cr1 & ~USART_CR1_TCIE;
u->SR = ~USART_SR_TC;
}
}
Just replace the current function with this one and see if you notice improvements.
Giovanni
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: Serrial communication massive data loss
No improvement I can see, still goes to overrun when I hit the 4mhz.
I'm afraid you might be chasing an error that might be related to clock instability, already asked my hardware guy to solder me an external crystal to test, just don't know when he will be available to do it.
I'm afraid you might be chasing an error that might be related to clock instability, already asked my hardware guy to solder me an external crystal to test, just don't know when he will be available to do it.
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Serrial communication massive data loss
I find it unlikely that it is unstable at 4MHz but not at 8MHz, try to obtain 4MHz from HSI instead of MSI, that would not be less stable that the 8MHz that work.
-
DrunkenDonkey
- Posts: 124
- Joined: Sun Aug 28, 2011 5:16 pm
Re: Serrial communication massive data loss
Both 4mhz from MSI and 4mhz from HSI result in overrun errors (and sometimes framing too). Going below that barely getting half the data and worse.