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.

MSPM0C1104: send Hex values to uart more than 4 bytes.

Part Number: MSPM0C1104

I am using MSPM0C1104 but having hard time in sending HEX value to uart and Please suggest me how can I send hex value to UART more than 4 bytes say #define OpenLid   {0x11,0x22, 0x33, 0x44,0x55,0x66};



Following is the source code.

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Configure the internal loopback mode.
* Note that data received on the UART RXD IO pin will be ignored when
* loopback is enabled.
*/
#define ENABLE_LOOPBACK_MODE true
/*
* Number of bytes for UART packet size
* The packet will be transmitted by the UART.
* This example uses FIFOs with polling, and the maximum FIFO size is 4.
* Refer to interrupt examples to handle larger packets.
*/
#define UART_PACKET_SIZE (4)
/* Delay for 5ms to ensure UART TX is idle before starting transmission */
#define UART_TX_DELAY (160000)
#define OpenLid {'M', 'S', 'P', '!'};//{0x11,0x22, 0x33, 0x44};
/* Data for UART to transmit */
uint8_t txPacket[UART_PACKET_SIZE];//= {'M', 'S', 'P', '!'};
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Harshita,

    I think all that is needed is to fill the txPacket[ ] with the hex values you want to send and pass the # of values to the UART_Write function.

  • What are you getting?

    Note that you do this:

    DL_UART_Main_fillTXFIFO(UART_0_INST, &txPacket[i], UART_PACKET_SIZE);

    I assume you want to send the 4 bytes in txPacket.

    You should forget about the for loop and write:

    DL_UART_Main_fillTXFIFO(UART_0_INST, &txPacket[0], UART_PACKET_SIZE);

    or use the for loop and do:

    DL_UART_Main_fillTXFIFO(UART_0_INST, &txPacket[i], 1);

  • unsigned char txPacket[UART_PACKET_SIZE];
    unsigned char arr[] = {0x11,0x22, 0x33, 0x44,0x66,0x88,0x77};
    I have assigned my arrays as unsigned char and this solved my issue. I am using sscom for serial view and enable show hex option in my terminal.


    But yet the open issue for me is I want to send more than 4 bytes in txPacket. Can you suggest how can I do that??

  • Hi Harshita,

    The issue is the UART FIFO can only hold up to 4 bytes.  To transmit more than 4, you will need to use a UART ISR handler to manage the additional bytes.

    Or you can use this driverlib function that sends only one byte at a time.  You can put it in a for() loop and send as many bytes as you want.

    /**
    * @brief Blocks to ensure transmit is ready before sending data
    *
    * Puts the data into the TX FIFO after blocking to ensure the TX FIFO is not
    * full. Will wait indefintely until there is space in the TX FIFO. See
    * related APIs for additional transmit options.
    *
    * Can be used for any data transfers that are less than or equal to 8 bits.
    *
    * @param[in] uart pointer to the register overlay for the peripheral
    * @param[in] data data to send
    *
    * @sa DL_UART_transmitData
    * @sa DL_UART_transmitDataCheck
    */
    void DL_UART_transmitDataBlocking(UART_Regs *uart, uint8_t data);

  • Hi Dennis,

    I facing one more error. Since I am sending HEX value from uart the receive values are also HEX.

    void UART_Write(uint8_t DataBuffer[],uint8_t size){

    /* Optional delay to ensure UART TX is idle before starting transmission */
    delay_cycles(UART_TX_DELAY);

    /* Set LED to indicate start of transfer */
    DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_USER_LED_1_PIN);

    for (int i=0; i<size; i++){
    /* Fills TX FIFO with data and transmits the data */
    // DL_UART_Main_fillTXFIFO(UART_0_INST, &txPacket[i], 1);
    DL_UART_transmitDataBlocking(UART_0_INST, txPacket[i]);

    }

    /* Wait until all bytes have been transmitted and the TX FIFO is empty */
    while (DL_UART_Main_isBusy(UART_0_INST))
    ;
    }

    void UART_Read(uint8_t size){
    /*
    * Wait to receive the UART data
    * This loop expects UART_PACKET_SIZE bytes
    */
    for (uint8_t i = 0; i < size; i++) {
    rxPacket[i] = DL_UART_receiveDataBlocking(UART_0_INST);
    }
    }

    Above is the functions. 
    Here I am passing unsigned char arr[] = {0x34,0x1A, 0x00, 0x0E ,0x71} to uart write function. 
    On Serial port uart tx data is 34 1A 00 0E  71 which is correct but Uart (read) rx data is D0 C0 C4 F8 E4 FE. But it should be 43 01 00 0E 71 (this response I should get on UART Read). 
    But anyway my UART slave is responding. And it will response only when it got the correct tx data. and There is nothing much to do with slave, As soon it get the command it will respond.

     
    On seial port I enabled show HEX option and write data is correct but read data is not correct. Where is the problem? What do I need to do on UART_READ to get correct HEX data. Typecasting or anything?

  • "On Serial port uart tx data is 34 1A 00 0E  71"

    Does this mean you checked it with a scope?

    If so, and the sender is sending the correct bytes at the correct baud, and the scope shows the correct bytes with the correct baud, it obviously is in the receiver.

    Is it set to the correct baud? Is there a clock error that might made the baud rate, say 10% off? Have you checked for overrun errors?

  • I am using BUSCLK clock source and my buadrate is 115200, OVS 16x. But Calculated buadrate is 115246.10 and %error is 0.04%. Does this cause the problem.

  • How about the receiver?

    Are you using crystals for your board?

  • Hi Harshita,

    Per Keith's suggestion, do you have an oscilloscope or logic probe that you can capture a screen shot of the data being transmitted?

  • Hey Dennis,
    I have figured out data transmission and getting right response on my comm port.
    But Need one more help,

    Following function I am using for uart read.

    void UART_Read(uint8_t size){
    /*
    * Wait to receive the UART data
    * This loop expects UART_PACKET_SIZE bytes
    */
    for (uint8_t i = 0; i < size; i++) {
    rxPacket[i] = DL_UART_receiveDataBlocking(UART_0_INST);
    }
    }

    In main(){

    SYSCFG_DL_init();

    -----

    ------

    While(1){

    ------

    -----

    -----

    UART_Write_buffer(arr, uart_packet_size);

    I2C_Write_buffer(REG_14,0x0B);
    // delay_cycles(8000000);

    UART_Read(uart_packet_size);  // Expected: If this function not successfully read package it will come out of this function and toggle led 

    DL_GPIO_togglePins(GPIO_LEDS_PORT,
    GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_TEST_PIN);
    delay_cycles(12000000);

    }

    }
    Here whenever slave is not sending uart rx package main function is stuck at uart_read() and not toggling and sending uart write again.

    I want even if Uart read is not successful main loop (keep on continue) send Uartwrite again and again until slave send a rx package. But here main loop stuck at uart_read and not moving forward. How do I proceed with my scenario what is the right API for UART Read based on my applications.

    Please help.

  • Hi Harshita,

    Looks like the function you are calling, UART_Read(), is a blocking function.  This means the function will not return until it receives a byte.  Inside this function, what MSPM0 driverlib UART function is called? 

    The following function definition does not block, but there is no guarantee if there is data there.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    /**
    * @brief Reads data from the RX FIFO
    *
    * Reads the data from the RX FIFO without checking its status. Use if
    * already sure the RX FIFO has data available. See related APIs for
    * additional receive options.
    *
    * @param[in] uart Pointer to the register overlay for the peripheral
    *
    * @return The data in the RX FIFO
    *
    * @sa DL_UART_receiveDataBlocking
    * @sa DL_UART_receiveDataCheck
    */
    __STATIC_INLINE uint8_t DL_UART_receiveData(UART_Regs *uart)
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Instead, I would recommend to first check to see if there is data in the FIFO by calling this function below before calling your UART_Read() function.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /**
    * @brief Checks the RX FIFO before trying to transmit data
    *
    * Checks if the RX FIFO is already empty before trying to read new data from
    * the FIFO. Exits immediately if empty rather than trying to block. See
    * related APIs for additional receive options.
    *
    * Can be used for any data transfers that are less than or equal to 8 bits.
    *
    * @param[in] uart pointer to the register overlay for the peripheral
    * @param[in] buffer a buffer to write the received data into
    *
    * @return If the receive occurred
    *
    * @retval true if data was read from the RX FIFO
    * @retval false if the RX FIFO was empty and data was not read
    *
    * @sa DL_UART_receiveData
    * @sa DL_UART_receiveDataBlocking
    */
    bool DL_UART_receiveDataCheck(UART_Regs *uart, uint8_t *buffer);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Code would look something like the following.  Obviously change the variable names to match what you are using your UART and buffer.

    Fullscreen
    1
    2
    if(DL_UART_receiveDataCheck(UART_0_INST, RxBuffer) == true)
    UART_Read(uart_packet_size);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi dennis,

    I want to check rxbuffer for whole data till uart_packet_size. But if this is having only one byte (DL_UART_receiveDataCheck(UART_0_INST, RxBuffer) function is true. But I want to check Rx buffer has all  uart_packet_size data then only UART_read will exrecute. Is there any way of doing this.

  • You need to put each byte as it comes in in a buffer and increment a size variable. You can create a UART_Check() function that will return the number of bytes received. If it is the right size, process the buffer.

    I do something like this in main. I am sending straight ASCII, so '\0' is out-of-band. I am also using lf and cr as end-of-packet markers, so I am not keeping track of the size:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    if (RXdata != 0) {
    data = RXdata;
    RXdata = 0;
    if ((data == '\r') || (data == '\n')) {
    // do the command
    // for now just, echo
    if (rxbufidx != 0) {
    // weed out naked \n's
    strcat(rxbuf, "\n\r");
    StartSerialTX(rxbuf);
    }
    // zero the buffer
    rxbuf[0] = '\0';
    rxbufidx = 0;
    } else {
    rxbuf[rxbufidx++] = data;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You could put the received data in a buffer and increment the count in the interrupt.

  • Thank you for sharing your code Keith.  Harshita, does this do what you are looking for?

  • Actually I am looking for doing without interrupt. As keith suggested to make UART_Check function, can we create it without interrupt. I'am using Uart Multibytes polling method.

  • What your UART_check() would do is see if a byte of data is available. If so, put it in a buffer. If you have received framesize bytes, set a flag. But depending on what the rest of the code is doing, you could lose bytes.

    The interrupt can do it all behind the scenes.

  • Hi keith and Dennis,

    Need one more solution on urgent basic. I am using MSPM01104 chipset VSSOP20 for my PCBA design. Here all pins are used except PA22 and PA23 which earlier I was using for test points. But now I want to make these pins as GPIO SW Uart. But As I am enabling PA22 as UART_GPIO_TX I am getting enable CLKOUT error. Please help me with this error.

    Currently selected CLK_OUT pin not available when routing a high frequency. Please select a different CLK_OUT source or a different pin. See device documentation for pin limitations.
  • PA22 is showing resource conflict. Is there any way to deal with this.

  • For high frequency clocks you need to divide them down to get the frequency to a level the GPIO can handle.

  • Hi keith, Can you help me with example code of SW GPIO uart.

  • I usually point people to the Arduino SoftwareSerial code, which implements a bit-banging UART.