The below tutorial to enable and use UART is by using the CC3200 SDK library version 1.1.0 but it will be compatible with other versions as well.
First let me list the library header files that are required for this program.
Considering UART1
- rom_map.h
- hw_memmap.h
- prcm.h/prcm.c
- pin.h/pin.c
- uart.h/uart.c
- uart_hal.h/uart_hal.c
//Enable the UART peripheral clock
MAP_PRCMPeripheralClkEnable(PRCM_UARTA1, PRCM_RUN_MODE_CLK);
//Pin Configuration
// Configure PIN_01 (GPIO_10) for UART1_TX
MAP_PinTypeUART(PIN_01, PIN_MODE_7);
MAP_PinTypeUART(PIN_01, PIN_MODE_7);
// Configure PIN_02 (GPIO_11) for UART1_RX
MAP_PinTypeUART(PIN_02, PIN_MODE_7);
MAP_PinTypeUART(PIN_02, PIN_MODE_7);
//Set the UART1 Configurations (Clock, Baudrate, Data, Stop and Parity bits)
MAP_UARTConfigSetExpClk(CONSOLE,MAP_PRCMPeripheralClockGet(CONSOLE_PERIPH), UART_BAUD_RATE, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
Now, the UART1 is configured to work with GPIO pins 10 (TX) and 11 (RX) with baud rate as defined by the macro UART_BAUD_RATE and data length of 8 bits, 1 stop bit and no parity check. You can also choose different pin sets such as GPIO_16 as TX and GPIO_17 as RX or any other pin sets as defined in the technical reference manual.
Lets look at APIs to send and receive data. There are API defined to send and receive data both in non-blocking and blocking (polling) methods.
Blocking Codes - Waits for data reception or transmission completion by entering a conditional loop and blocking the cpu.
Non-Blocking Codes - Looks for data, data is retrieved if available or else, it continues executing the next instruction.
//Blocking codes
//Receive data
Data = UARTCharGet(UARTA1_BASE);
//Send data
UARTCharPut(UARTA1_BASE, Data);
//Non-Blocking codes
//Receive data
Data = UARTCharGetNonBlocking(UART1_BASE);
//Send data
UARTCharPutNonBlocking(UARTA1_BASE, Data);
Here, UART1_BASE is a macro defining the base memory location of UART1 as given in memory map in the Datasheet and is defined in hw_memmap.h. The variable 'Data' is the data received or sent. By using the UARTCharGet or UARTCharPut API inside a loop a string of data can be sent over serial port.
In the SDK, there are functions prefixed with 'MAP_' which are macros defined in rom_map.h which actually maps to the memory location of internal ROM where these APIs are pre-written as part of the servicepack. This reduces the size of binary file and serial flash utilization.
In the SDK, there are functions prefixed with 'MAP_' which are macros defined in rom_map.h which actually maps to the memory location of internal ROM where these APIs are pre-written as part of the servicepack. This reduces the size of binary file and serial flash utilization.
UART can also be used with interrupt enabled. For UART interrupt handling, visit CC3200 Launchpad - UART Interrupt handling.
No comments:
Post a Comment
Comment will be published after moderation only. Do not advertise here.