Dear Intel and Edison Community,
I tried to use the Edison MCU in my project to perform low level tasks such as receiving data from the host and sending via UART1 (and in the opposite direction) with manual flow control (for RS485), but I've encountered some problems.
# include "mcu_api.h"
# include "mcu_errno.h"
# define MAX_BUF 255
unsigned char buf[MAX_BUF];
unsigned char buf_r;
if (uart_read(1, &buf_r, 1)>=0)
unsigned int len;
len = host_receive(buf, MAX_BUF);
uart_write(1, buf, len);
Using uart_read function (which is a non-blocking only when reading one byte), I can not know the number of the received bytes. Therefore, even when really nothing to read - we get the garbage bytes via host_send. Is there any way to fix it?
With the MPAA we can flexibly manage the UART http://iotdk.intel.com/docs/mraa/v1.5.1/uart_8h.html mraa: /iotdk/jenkins/workspace/mraa-doc-stable/api/mraa/uart.h File Reference , but with MCU API we have only 3 functions.
Thanks for reaching out.
Well, I'm not sure if it is possible to know the number of received bytes, but did you try with MAX_BUF instead of 1 on the functions uart_read and host send?
The function uart_read returns 0 if it is successful, I think that you get garbage because you are using the if with >=0.
With all that said, I recommend you to use the following lines:
if (uart_read(1, &buf_r, MAX_BUF)==0)host_send(&buf_r, MAX_BUF);
Let me know if it works.
Thanks for the answer.
I try it and in this case uart_read is blocking (wait until it is read MAX_BUF bytes). Changing >=0 to ==0 also did not help: uart_read always return 0, even if in reality the data has not been sent to the UART (Therefore, I can not understand what has been read - data or garbage).
I think this is not possible with the APIs to access UART, I recommend you to use another GPIO as a flag, that indicates when the data is in the port.
You can also check the example to read from UART in your folder: MCU_SDK_HOME/docs/api_doc/html/sample__uart__receive_8c_source.html, it is the only information available to read data from UART.
I hope you find this information useful.
I was wondering if you have updates on this. Was my recommendation useful?
Remember that we are here to help you.