Page 1 of 1

Issue using TD_UART_GetChar

Posted: Wed Jun 22, 2016 4:40 pm
by axelC
Hello,

I have an issue implementing UART reading and TD_UART_GetChar function.
With SDK 6.3.2 on a TD1204

I init my uart line in TD_USER_Setup()
Code: Select all
   init_printf(TD_UART_Init(   9600,   //Baudrate
                        true,    //RX Enable
                        true),   //Pin Shared
            TD_UART_Putc,
            TD_UART_Start,
            TD_UART_Stop);


and I just did a first test in TD_USER_Loop() with:

Code: Select all
   while ((c = TD_UART_GetChar()) >= 0) {
      tfp_printf(   "char : %c - %x\r\n", c, c);
   }


After the execution of TD_USER_Setup(void) I have an infinite return on serial port (without pressing any key) full of :

Code: Select all
char : ÿ - ff
char : ÿ - ff
char : ÿ - ff
char : ÿ - ff
char : ÿ - ff


I tried to add
Code: Select all
GPIO_PinModeSet(RX_PORT, RX_BIT, gpioModeInput, 0);

Before the uart init but it make the same issue.


For info, I have a led on the tx pin but nothing on the rx pin. That why I use the Pin Shared function. Could it be the issue?
But I have the same comportment with
Code: Select all
   init_printf(TD_UART_Init(   9600,   //Baudrate
                        true,    //RX Enable
                        false),   //Pin Shared
            TD_UART_Putc,
            TD_UART_Start,
            TD_UART_Stop);


Does anyone know why the TD_UART_GetChar function would always return 0xFF?

Re: Issue using TD_UART_GetChar

Posted: Thu Jun 23, 2016 7:44 am
by axelC
After a night of sleep I found the reason,
c was declared as char instead of int.

TD_UART_GetChar return an int that can be cast as char after the >= 0 test

Working code:

Code: Select all
void TD_USER_Loop(void)
{
   int c;

   // Process geoloc events
   TD_GEOLOC_Process();

   // Process Accelerometer events
   TD_ACCELERO_Process();

   while ((c = TD_UART_GetChar()) >= 0) {
      tfp_printf(   "char : %c - %x\r\n", c, c);
   }
}

Re: Issue using TD_UART_GetChar

Posted: Thu Jun 23, 2016 9:26 am
by axelC
Actually I still have an issue,

I can't use the shared option.
When I put true to shared in :

Code: Select all
   init_printf(TD_UART_Init(   9600,   //Baudrate
                        true,    //RX Enable
                        true),   //Pin Shared
            TD_UART_Putc,
            TD_UART_Start,
            TD_UART_Stop);


The Rx function doesn't work anymore.

Only my tx pin is shared with a LED why the Rx doesn't work in shared mode?

Re: Issue using TD_UART_GetChar

Posted: Fri Aug 26, 2016 11:56 am
by axelC
Same comportment with
Code: Select all
    TD_UART_Options_t options = {   LEUART_DEVICE,
                                    LEUART_LOCATION,
                                    TEST_BAUDRATE, 8, 'N', 1,
                                    true};                     //Pin Shared

    TD_UART_Open(&options, TD_STREAM_RDWR);