Hi, Senlent
Thank you so much for your support.
I found that the baudrate of the existing code was actually changable by monitoring a waveform with oscilloscope.
The problems is that the code example below works in 500kbps, but doesn't work in 1Mbps.
The function __read_register() is a code implemented to read registers of the certain LED driver IC after sending a read command through UART_TX to the IC and filling up read buffers.
I think that the sub-functions are not stable and they could cause errors in 1Mbps.
Could you correct the sub-functions below?
Or, Could you send an example code is able to transmit, receive and handle multiple bytes?
Uart__Clear_RXbuffer(uint8_t len)
Uart__Clear_RXbuffer(uint8_t len)
Uart__send_TX(uint8_t buffer[], uint16_t *length)
[Example code]
static bool __read_register(uint8_t frame_init, uint8_t lmmAddr, uint8_t regAddr, uint8_t readBuffer[], uint8_t lenByte)
{
uint8_t txBuffer[RegBufferLength], read_length, pos, retry_cnt = 0;
uint16_t txBufferLength = 0;
read_length = 5 + lenByte + read_CRC_Len;
pos = read_length - (lenByte + read_CRC_Len);
do
{
if((++retry_cnt) > 3)
{
return false;
}
Uart__Clear_RXbuffer(read_length); //read_length is only used for clearing read buffers. (It's kind of transmit buffer to send rather than read buffer length)
UserDefine__Delay_ms(1);
__write_RegisterBuffer(frame_init, lmmAddr, regAddr, NULL, 0, txBuffer, &txBufferLength); //Fill buffer to send including Frame_INIT, lmmAddr, regAddr, CRCH, CRCL)
UserDefine__Delay_ms(1);
Uart__send_TX(txBuffer, &txBufferLength); //send buffer data through actual UART. uint8_t buffer[], uint16_t *length
UserDefine__Delay_ms(1);
} while (!Uart__Read_RXbuffer(read_length, readBuffer)); //read until readBuffer to empty
//not related to actual register, just fill the buffer until read data end.
for(uint8_t i = 0; i < lenByte; i++)
{
readBuffer[i] = readBuffer[pos + i]; //Excluding not data information(CRCL,H), only allocating DATA to readBuffer[]....[]
//UserDefine__Delay_ms(1);
}
//UserDefine__Delay_ms(1);
return true;
}
void Uart__Clear_RXbuffer(uint8_t len)
{
status_t status;
Rx_bufferIdx = 0;
for(uint8_t i = 0; i < len; i++)
{
Rx_buffer[i] = 0;
}
LPUART_DRV_ReceiveData(INST_LPUART1, Rx_buffer, len);
}
void Uart__Clear_RXbuffer(uint8_t len)
{
status_t status;
Rx_bufferIdx = 0;
for(uint8_t i = 0; i < len; i++)
{
Rx_buffer[i] = 0;
}
LPUART_DRV_ReceiveData(INST_LPUART1, Rx_buffer, len);
}
void Uart__send_TX(uint8_t buffer[], uint16_t *length)
{
LPUART_DRV_SendDataBlocking(INST_LPUART1, buffer, *length, UART_TIMEOUT);
*length = 0;
}