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.
/*
* 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', '!'};
/* Data received from UART */
uint8_t rxPacket[UART_PACKET_SIZE];
void UART_Write_buffer(uint8_t *data, int size);
void UART_Write(uint8_t *DataBuffer,uint8_t size);
void UART_Write_buffer(uint8_t *data, int size) {
for (int i=0; i<size; i++){
txPacket[i] = data[i]; //register
}
UART_Write( txPacket, size);
}
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], UART_PACKET_SIZE);
}
/* Wait until all bytes have been transmitted and the TX FIFO is empty */
while (DL_UART_Main_isBusy(UART_0_INST))
;
}
int main(void)
{
SYSCFG_DL_init();
// /*
// * Wait to receive the UART data
// * This loop expects UART_PACKET_SIZE bytes
// */
// for (uint8_t i = 0; i < UART_PACKET_SIZE; i++) {
// rxPacket[i] = DL_UART_receiveDataBlocking(UART_0_INST);
// }
/* If write and read were successful, toggle LED */
while (1) {
uint8_t arr[] = OpenLid;
UART_Write_buffer(arr, 5);
//UART_Write(txPacket,4);
DL_GPIO_togglePins(GPIO_LEDS_PORT,
GPIO_LEDS_USER_LED_1_PIN | GPIO_LEDS_USER_TEST_PIN);
delay_cycles(1200000);
}
}