I have a weird behaviour when using TD_UART_SendBuffer();
The TD1208 is connected through its RX-TX pins to a microcontroller (LPC1768) and use Modbus protocol. The TD1208 is master and Reads Input Registers of the LPC.
I use two messages to read two sets of registers. I have no trouble with the first but with the second, the sent bytes are not the one expected. Let me explain:
First modbus message:
- Code: Select all
void modbusConsumpt1Request (void) {
uint8_t sfOutBuffer[8];
uint16_t i = 0;
sfOutBuffer[i++] = 0x02; //address
sfOutBuffer[i++] = 0x04; //functioncode
sfOutBuffer[i++] = 0x00; //start add HI
sfOutBuffer[i++] = 0x02; //start add LO
sfOutBuffer[i++] = 0x00; //qt input reg HI
sfOutBuffer[i++] = 0x02; //qt input reg LO
sfOutBuffer[i++] = 0xd0; //CRC1
sfOutBuffer[i++] = 0x38; //CRC2
TD_UART_SendBuffer (uartdescript, (void*) sfOutBuffer, i);
}
I have no trouble and the LPC answers correctly.
Second message:
- Code: Select all
void modbusConsumpt2Request (void) {
uint8_t sfOutBuffer2[8];
uint16_t i = 0;
sfOutBuffer2[i++] = 0x02; //address
sfOutBuffer2[i++] = 0x04; //functioncode
sfOutBuffer2[i++] = 0x00; //start add HI
sfOutBuffer2[i++] = 0x0c; //start add LO
sfOutBuffer2[i++] = 0x00; //qt input reg HI
sfOutBuffer2[i++] = 0x02; //qt input reg LO
sfOutBuffer2[i++] = 0xb1; //CRC1
sfOutBuffer2[i++] = 0xfb; //CRC2
TD_UART_SendBuffer (uartdescript, (void*) sfOutBuffer2, i);
}
With modbusConsumpt2Request, the four first bytes coming out of the TD1208 are correct but the following ones are incorrect. They have random values.
Does anyone have an explanation ? Maybe a method to debug this ?
Thank you,