Hello!
I have a brushless DC motor with an appropriate driver (TMCM1640). My K64F communicates via a RS485 transceiver (Artekit RS485/HD) with the RS485 interface of that driver. I am using the uart_nonblocking example code from the KDS library to send data. Uart is configured with the RTS flow control like so:
UART_DRV_Init(UART_INSTANCE_2, &uartState2, &uartConfig); UART_HAL_SetTransmitterRtsCmd(UART2_BASE_PTR, true); UART_HAL_SetTransmitterRtsPolarityMode(UART2_BASE_PTR,true);
(and some other lines...)
In the main loop I use
UART_DRV_SendData(UART_INSTANCE_2, &setTargetCurrentZeroCom , 9u);
while (kStatus_UART_TxBusy == UART_DRV_GetTransmitStatus(UART_INSTANCE_2, NULL)){}
UART_DRV_ReceiveData(UART_INSTANCE_2, &rxChar, 9u);
while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(UART_INSTANCE_2, NULL)){}
to send a 9 byte command and then receive the 9 byte answer from the module. I have two problems with that and maybe this forum can answer them. I get the information, who sends what vie oscilloscope, btw.
1) The command and answer loop goes on a certain amount of times at the 9600 or 115200 Baudrate for example, then it stops. Can be a few commands to a couple of hundreds. But after a while the module sends an answer and the mcu does not get it. Because of the while loops in the main loop the code gets stuck and I see the error --> wait forever to receive. Why would it work for a few times and then stop?
What other information would you need to be able to give advice? Am I missing something simple here?
Thanks,
best regards,
Michael
Hello, again!
I have to admit, that I don't know why, but now the following behaviour is now observable:
Every time the program on the mcu is started, there is a command and an answer back exactly 88 times. Then it stops. Every time. Is there a counter I don't know about?
Best regards,
Michael
Hi, Michael,
I am sorry for the delay, have you solved your problem? Regarding your issue, as far as I know, RS485 uses multiple slave/one master protocol. If you use uart_nonblocking methos based on KSDK2.0, pls refer to the example:
C:\SDK2.0_K64F\boards\frdmk64f\driver_examples\uart
especially, the example.
C:\SDK2.0_K64F\boards\frdmk64f\driver_examples\uart\interrupt_transfer\kds
In the example, the basic concept is that you call the UART_TransferSendNonBlocking(), when all the predefined number of bytes has been transferred, the callback() function is called.
Hope it can help you.
BR
XiangJun Rong
Hello! Sorry to answer so late. Yes I have solved the problem. After correctly configuring the physical setup, it works nicely. Thanks for the suggestion!
Cheers,
Michael