Max serial buffer AsynchroSerial HCS08

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Max serial buffer AsynchroSerial HCS08

296 Views
a_cavazzana
Contributor I

Hi. I think I found a bug in the serial buffer declaration on an hcs08. Input/Output buffer sizes have an admissible range from 0 to 65535 byte so ,in my project (for compatibility with standard modbus, max registers readable is 125 --> 257  byte), i've set 260 byte. After this, during the communication, sometimes the mcu resets!!. So i've find in the processorExpert's library this:

byte MODBUS_SLAVE_RecvChar(MODBUS_SLAVE_TComData *Chr)
{
byte Result = ERR_OK; /* Prepare default error code */

if (MODBUS_SLAVE_InpLen > 0U) { /* Is number of received chars greater than 0? */
EnterCritical(); /* Save the PS register */
MODBUS_SLAVE_InpLen--; /* Decrease number of received chars */
*Chr = InpBuffer[InpIndxR]; /* Received char */
if (++InpIndxR >= MODBUS_SLAVE_INP_BUF_SIZE) { /* Is the index out of the buffer? */
InpIndxR = 0U; /* Set the index to the start of the buffer */
}
Result = (byte)((SerFlag & (OVERRUN_ERR|COMMON_ERR|FULL_RX)) ? ERR_COMMON : ERR_OK);
SerFlag &= (byte)(~(byte)(OVERRUN_ERR|COMMON_ERR|FULL_RX|CHAR_IN_RX)); /* Clear all errors in the status variable */
ExitCritical(); /* Restore the PS register */
} else {
return ERR_RXEMPTY; /* Receiver is empty */
}
return Result; /* Return error code */
}

and InpIndx and other variables are BYTES!!

byte MODBUS_SLAVE_InpLen;       /* Length of the input buffer content */
static byte InpIndxR;                         /* Index for reading from input buffer */
static byte InpIndxW;                         /* Index for writing to input buffer */
static MODBUS_SLAVE_TComData InpBuffer[MODBUS_SLAVE_INP_BUF_SIZE];          /* Input buffer for SCI commmunication */
byte MODBUS_SLAVE_OutLen;             /* Length of the output buffer content */
static byte OutIndxR;             /* Index for reading from output buffer */
static byte OutIndxW;             /* Index for writing to output buffer */
static MODBUS_SLAVE_TComData OutBuffer[MODBUS_SLAVE_OUT_BUF_SIZE];         /* Output buffer for SCI commmunication */

Changing from 260 to 255 the buffer declaration, it works.

 Are corrected my considerations? Can you verify ? Thanks

0 Kudos
0 Replies