Friday, 15 January 2010

microcontroller - Circular buffer pointer irregularities -


This is the follow-up on this question:.

After applying one to the microcontroller, it seems that there is a problem with the indicator

sent to RS-232: ADE 1234
Received (buffer = 8): E24AE2 / E2AE24 (Flix between the two) received (buffer = 16): D234E1 (A has been omitted because it is a synchronized byte (RX_BufSize = 32): DE1223 / DEE123 / DE1234 / DE12E1 (flip randomly received): Expected receive: DE1234

< P> Start

  Source: Thim 207 BTS Ektroniks - Académie de Strasbourg #define RX_BufSize 8 // Tayl Doo Bfr_araks four Bfr_araks [RX_BufSize]; // buffer circularie D reception four * ptrRX_WRdata = Buffer_RX; // bureau DRX four times * ptrRX_RDdata = buffer_rx; // burer DRX unsigned Charles Buffer_Cmd [7];  

The debug value displayed on the LCD

  // Printed debug value. The decoded output is seen through the U2 Beef Dispstring (-62, 17, 0, "Ply 2"); Four U2buf [] = {slave_command, slave_pal_d, slave_bal_x, slave_bal_y, slave_point_a, slave_point_b, '\ 0'}; Disp_string (-37, 17, 1, U2buf); Four U3buf [] = {buffer_rx [0], buffer_rx [1], buffer_rx [2], buffer_rx [3], buffer_rx [4], buffer_rx [5], buffer_rx [6], buffer_rx [7], '0} ; Disp_string (-37, 27, 1, U3buf); Four U4buf [] = {buffer CMD [0], buffer_cmd [1], buffer_cmd [2], buffer_cmd [3], buffer_cmd [4], buffer_cmd [5], buffer_cmd [6], '\ 0'}; Disp_string (-37, 7, 1, U4buf);  

get the interrupt

  zero _Isr _NOPSV _U1RXInterrupt (zero) {IFS0bits.U1RXIF = 0; While (U1STAbits.URXDA) {* ptrRX_WRdata ++ = U1RXREG; If (ptrRX_WRdata == buffer_x + Rxblufcease) ptrRX_WRdata = buffer_rx; } If (U1STAbits.OERR) {U1STAbits.OERR = 0; }}  

Work from source

  int ReadRXD (char * c) {if (ptrRX_RDdata == ptrRX_WRdata) Return (0); // Pas de caractère reçu else {* c = * ptrRX_RDdata ++; If (ptrRX_RDdata == Buffer_RX + RX_BufSize) ptrRX_RDdata = Buffer_RX; Return (1); }} Zero Detect_Cmd_RXD (zero) {int i; Four c; If (ReadRXD (& amp; c)); ACL_XY_AFFICHER_CARACTERE (5, 3, 256 + 'z', 1); ACL_XY_AFFICHER_CARACTERE (25, 3, 256 + C, 1); For (i = 1; i & lt; 7; i ++) buffer_cmd [i-1] = buffer_cmd [i]; Buffer_Cmd [6] = c; If (buffer_m [0] == 'A') {// & amp; (Buffer_cmd [4] == 0xAA)) {ACL_XY_AFFICHER_CARACTERE (15, 3, 256 + 'Q', 1); Slave_command = buffer_cmd [1]; Slave_pal_d = buffer_mmd [2]; If (system_player == 2) {slave_bal_x = buffer_cmd [3]; Slave_bal_y = buffer_cmd [4]; Slave_point_a = buffer_mmd [5]; Slave_point_b = buffer_mdm [6]; }}}  

Detect_Cmd_RXD is called the second at every 1/256th position. During that time, at least 7 values ​​will be sent in the UART received buffer.

Could it be possible that the process of writing is so fast that it gets caught on reading indicator? What can I do to solve this problem, besides calling Detect_Cmd_RXD most often? First step: If there is a buffer overrush in blockage obstruction, then check for overflow in Detect_Cmd_RXD routine. See that changing the buffer size affects the number of overruns.

The second step: If you reach the buffer size where there is no overrun, and there is still corruption, take a good look at the interrupt routine. UARS can be very sensitive to how you can reach your registrars, or order the operations, check the hardware datasheet and verify that you are reading it correctly - still better, find some sample code that you can do Wish, does the same type. Replacing characters when buffer size is 32, you may be recording data twice before getting the chance to settle down with the status bit.


No comments:

Post a Comment