This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

simpleCentral - UART implementation



Hi,

I'm working with simpleCentral with some changes and I would like to implement a UART to communicate from time to time with a SIM module (SIM808) to send a SMS, for that I need to send "AT" commands and verify the answer. Do you know if can implement that with normal UART? 

static UART_Handle uart1;
static UART_Params uartParams;

.
.
.

  /* Create a UART with data processing off. */
  UART_Params_init(&uartParams);
  uartParams.stopBits = UART_STOP_ONE;
  uartParams.writeDataMode = UART_DATA_BINARY;
  uartParams.readDataMode = UART_DATA_BINARY;
  uartParams.readReturnMode = UART_RETURN_FULL;
  uartParams.readEcho = UART_ECHO_OFF;
  uartParams.baudRate = 9600;         //Baudrate mais adequado

  uart1 = UART_open(Board_UART0, &uartParams);

  if (uart1 == NULL) {
      System_printf("Error opening UART\n");
  }

If can be possible, what I need to do?

Thank you,

Miguel Vieira

  • The UART driver has basic write and read APIs.

    I suppose you'd just have to implements UART_write() calls that sends ASCII "AT" commands and then use UART_read() to read in the "AT" responses.

    I'd take a look at the UART driver documentation or even the UART Echo example from TI-RTOS or the Simplelink CC2640R2 SDK.

    Tom

  • Hi Tom,

    I used the echo example to test UART and modified it to send AT commands to the GSM module. When I migrate my code to a program with BLE (like simpleCentral), my program stuck when i tried to do a UART_write(). Should I use something for correct program function?

    Thank you,

    Miguel

  • There is a blocking and callback mode on this driver. It's important that you call UART_write() only from a TI-RTOS Task context. Do not use a clock function (it's a Swi context) or within a callback handler that comes from an interrupt (Hwi function).

    Also, you can use ROV and see what Task is running. Perhaps you were able to successfully unblock a higher priority task which is starving your task calling UART_write().
  • Hi Tom,

    So UART should work even in blocking or callback mode, the problem is probably the tasks are trying to "work" at same time, right? What do you suggest, should I use a semaphore?

    Thank you,

    Miguel
  • It's up to you. Callback mode is trickier, but it allows you to continue task execution after calling UART_write/read(). To keep things simple, I'd suggest blocking if you're prototyping right now.
  • Hi Tom,

    Thank you for your answers. I'm implementing UART and I can send info thru it. I configure the UART Pins to RF2.8 for RX and RF2.10 for TX (SmartRF06 EB) and use an external device to see the messages through the PC and i'm seeing anything, appears as send "x" bytes. It is possible that are some other pins? I already check all Board files and configure them for my pins.

    Thank you
    Miguel Vieira
  • Hi Tom,

    Forget my previous answer (May 23, 2017 9:58 PM). I can send data using UART with the pins configured my me, the problem is when I use UART_write(), it takes alot of time to send the data. Do you know why? and what I can do to change that?

    Thank you,
    Miguel Vieira
  • Increase your baud rate to 115200 or so. Even with that, UART is relatively slow, so you need to be mindful where you call UART_write(). I've seen folks trying to write debug statements with this, just to mess up their system's timing.
  • I tried that and it's the same. The data only reach the target minutes later. Could be some buffer? or something like that? I'm using a clock too, could the clock affect the uart? I can post some of my code.

    Thank you,

    Miguel

  • Posting the code would help.
  • Main task:

    static void SimpleBLECentral_taskFxn(UArg a0, UArg a1)
    {
      // Initialize application
      SimpleBLECentral_init();
    
      // Application main loop
      for (;;)
      {
        // Waits for a signal to the semaphore associated with the calling thread.
        // Note that the semaphore associated with a thread is signaled when a
        // message is queued to the message receive queue of the thread or when
        // ICall_signal() function is called onto the semaphore.
        ICall_Errno errno = ICall_wait(ICALL_TIMEOUT_FOREVER);
    
        if (errno == ICALL_ERRNO_SUCCESS)
        {
          ICall_EntityID dest;
          ICall_ServiceEnum src;
          ICall_HciExtEvt *pMsg = NULL;
    
          if (ICall_fetchServiceMsg(&src, &dest,
                                    (void **)&pMsg) == ICALL_ERRNO_SUCCESS)
          {
            if ((src == ICALL_SERVICE_CLASS_BLE) && (dest == selfEntity))
            {
              // Process inter-task message
              SimpleBLECentral_processStackMsg((ICall_Hdr *)pMsg);
            }
    
            if (pMsg)
            {
              ICall_freeMsg(pMsg);
            }
          }
        }
    
        // If RTOS queue is not empty, process app message
        while (!Queue_empty(appMsgQueue))
        {
            mix_str *pMsgEvt = (mix_str *)Util_dequeueMsg(appMsgQueue);
            sbcEvt_t *pMsgEvt1 = (sbcEvt_t *)pMsgEvt;
            //app_msg_t *pMsgApp = (app_msg_t *)pMsgEvt;
            //char_data_t *pCharData = (char_data_t *)pMsgApp->pdu;
    
            if (pMsgEvt1)
            {
                //Display_print1(dispHandle, 3, 0, "%d",pMsgEvt1->hdr.event);
                SimpleBLECentral_processAppMsg(pMsgEvt1);
            }
            ICall_free(pMsgEvt);
        }
    
        if (events & SBC_START_DISCOVERY_EVT)
        {
          events &= ~SBC_START_DISCOVERY_EVT;
    
          SimpleBLECentral_startDiscovery();
        }
    
        Display_print0(dispHandle, 2, 0, "Main task");
    
        //Semaphore_post(Semaphore_handle(&semGSM));
        GSM_Proccess();
    
        //powerOff();
      }
    }

    UART configuration:

      UART_init();
    
      UART_Params_init(&uartParams);
      uartParams.stopBits = UART_STOP_ONE;
      uartParams.writeDataMode = UART_DATA_BINARY;
      uartParams.readDataMode = UART_DATA_BINARY;
      uartParams.readReturnMode = UART_RETURN_FULL;
      uartParams.readEcho = UART_ECHO_OFF;
      uartParams.baudRate = 9600;         //Baudrate mais adequado - 9600
    
      uart1 = UART_open(Board_UART0, &uartParams);
    
      if (uart1 == NULL) {
          System_printf("Error opening UART\n");
      }

    Function that uses UART:

    static void GSM_Proccess(){
    
        int x;
        char * text;
        Task_block(Task_handle(&sbcTask));
    
        powerOn();
        //Task_sleep(200000 / Clock_tickPeriod);     //1000 - 2ms
        _delay_cycles(90000000);
    
        // Se não ouver mais nada para fazer envia mensagem via uart
        x = UART_write(uart1, "AT+CREG?", 8);
        UART_write(uart1, &cr, sizeof(cr));
    
    }

    In this version, I used task_block and that way the commands are immediately sent.

    If you know a better solution, or "the solution", please let me know.

    Thank you,

    Miguel