Overview
This chapter describes the features and operation of the serial communication interface (SCI) module. SCI is a two−wire asynchronous serial port, commonly known as a UART. The SCI modules support digital communications between the CPU and other asynchronous peripherals that use the standard non-return to zero (NRZ) format. The SCI receiver and transmitter each have a 16-level deep FIFO for reducing servicing overhead, and each has its own separate enable and interrupt bits. Both can be operated independently for half-duplex communication, or simultaneously for full-duplex communication.
To specify data integrity, the SCI checks received data for break detection, parity, overrun and framing errors. The bit rate is programmable to different speeds through a 16-bit baud-select register.
Features of the SCI module include:
• Two external pins:
– SCITXD: SCI transmit-output pin
– SCIRXD: SCI receive-input pin
Both pins can be used as GPIO if not used for SCI.
• Baud rate programmable to 64K different rates
• Data-word format
– One start bit
– Data-word length programmable from one to eight bits
– Optional even/odd/no parity bit
– One or two-stop bits
– An extra bit to distinguish addresses from data (address bit mode only)
• Four error-detection flags: parity, overrun, framing, and break detection
• Two wake-up multiprocessor modes: idle-line and address bit
• Half- or full-duplex operation
• Double-buffered receive and transmit functions
• Transmitter and receiver operations can be accomplished through interrupt-driven or polled algorithms
with status flags.
• Separate enable bits for transmitter and receiver interrupts (except BRKDT)
• NRZ (non-return-to-zero) format
Figure 19-2. Serial Communications Interface (SCI) Module Block Diagram
Architecture
The significant elements used in the full-duplex operation are shown in Figure 19-2 and include:
• A transmitter (TX) and its major registers (upper half of Figure 19-2)
– SCITXBUF — transmitter data buffer register. Contains data (loaded by the CPU) to be transmitted
– TXSHF register — transmitter shift register. Accepts data from registered SCITXBUF and shifts data
onto the SCITXD pin, one bit at a time
• A receiver (RX) and its major registers (lower half of Figure 19-2)
– RXSHF register — receiver shift register. Shifts data in from SCIRXD pin, one bit at a time
– SCIRXBUF — receiver data buffer register. Contains data to be read by the CPU. Data from a remote processor is loaded into register RXSHF and then into registers SCIRXBUF and SCIRXEMU
• A programmable baud generator
• Control and status registers
The SCI receiver and transmitter can operate either independently or simultaneously.
SCI Module Signal Summary
SCI Programmable Data Format
SCI data, both receive and transmit, is in NRZ (non-return-to-zero) format. The NRZ data format, shown in Figure 19-3, consists of:
• One start bit
• One to eight data bits
• An even/odd parity bit (optional)
• One or two stop bits
An extra bit to distinguish addresses from data (address-bit mode only)The basic unit of data is called a character and is one to eight bits in length. Each character of data is formatted with a start bit, one or two stop bits, and optional parity and address bits. A character of data with its formatting information is called a frame and is shown in Figure 19-3.
To program the data format, use the SCICCR register. The bits used to program the data format are shown in Table 19-2.
SCI Baud Rate Calculations
The internally generated serial clock is determined by the low-speed peripheral clock LSPCLK) and the baud-select registers. The SCI uses the 16-bit value of the baud-select registers to select one of the 64K different serial clock rates possible for a given LSPCLK.
See the bit descriptions in the baud-select registers, for the formula to use when calculating the SCI asynchronous baud. Table 19-3 shows the baud-select values for common SCI bit rates.
Bill of Materials
S.No | Component Name | Quantity | |
1 | LAUNCHXL-F28379D | 1 | https://evelta.com/launchxl-f28379d-c2000 |
2 | USB TO UART | 1 | https://www.amazon.in/xcluma-FT232Rl-Serial-Adaptor |
Breadboard | 1 | https://www.amazon.in/Robotbanao-Solderless-MB102-Breadboard1 | |
3 | Male to Female Jumper Wires | 20 | https://www.amazon.in/YUVS-Jumper-Wires |
SCIA serial communication configuration steps
1.1 Initialization SCIA corresponds to GPIO (Method_1)
void UART_GPIO_init(){
//SCIB -> SCI0 Pinmux
GPIO_setPinConfig(GPIO_43_SCIRXDA);
GPIO_setPinConfig(GPIO_42_SCITXDA);
}
1. 1.1 Initialization SCIA corresponds to GPIO (Method_2)
void UART_GPIO_init(){
// GPIO43 is the SCI Rx pin.
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_SCIRXDA, GPIO_CORE_CPU1);
GPIO_setPinConfig(DEVICE_GPIO_CFG_SCIRXDA);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCIRXDA, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCIRXDA, GPIO_QUAL_ASYNC);
//
// GPIO42 is the SCI Tx pin.
//
GPIO_setMasterCore(DEVICE_GPIO_PIN_SCITXDA, GPIO_CORE_CPU1);
GPIO_setPinConfig(DEVICE_GPIO_CFG_SCITXDA);
GPIO_setDirectionMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(DEVICE_GPIO_PIN_SCITXDA, GPIO_PIN_TYPE_STD);
GPIO_setQualificationMode(DEVICE_GPIO_PIN_SCITXDA, GPIO_QUAL_ASYNC);
}
1.2 Data format and Baud Rate
void SCI_A_init(){
SCI_performSoftwareReset(SCIA_BASE);
//
// Configure SCIA for echoback.
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_resetChannels(SCIA_BASE);
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
SCI_enableModule(SCIA_BASE);
SCI_performSoftwareReset(SCIA_BASE);
//
// Enable the TXRDY and RXRDY interrupts.
//
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
#ifdef AUTOBAUD
//
// Perform an autobaud lock.
// SCI expects an 'a' or 'A' to lock the baud rate.
//
SCI_lockAutobaud(SCIA_BASE);
#endif
}
Serial Communication Using Polling Method
Final Code
/*
* main.c
*
* Created on: Sep 28, 2021
* Author: Admin
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "F28x_Project.h"
#include "F2837xD_device.h"
#include "F2837xD_Examples.h"
#include "device.h"
#include "driverlib.h"
#define EMPTY_LOOP
#define ENDLESS 1
void UART_GPIO_init();
void SCI_A_init();
void uart_tx_bite(uint16_t a);
void hal_PutsUART(char * s);
char tx_data = '0';
void main(void)
{
Device_init();
Device_initGPIO();
UART_GPIO_init();
SCI_A_init();
while(1)
{
SCI_writeCharArray(SCIA_BASE, (uint16_t *)"MEVI HUB\r\n", sizeof("MEVI HUB\r\n"));
DEVICE_DELAY_US(1000000);
}
}
void UART_GPIO_init(){
//SCIB -> SCI0 Pinmux
GPIO_setPinConfig(GPIO_43_SCIRXDA);
GPIO_setPinConfig(GPIO_42_SCITXDA);
}
void SCI_A_init(){
SCI_performSoftwareReset(SCIA_BASE);
//
// Configure SCIA for echoback.
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_resetChannels(SCIA_BASE);
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
SCI_enableModule(SCIA_BASE);
SCI_performSoftwareReset(SCIA_BASE);
//
// Enable the TXRDY and RXRDY interrupts.
//
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
#ifdef AUTOBAUD
//
// Perform an autobaud lock.
// SCI expects an 'a' or 'A' to lock the baud rate.
//
SCI_lockAutobaud(SCIA_BASE);
#endif
}
Serial Communication Using Interrupt Method
Final Code
/*
* main.c
*
* Created on: 09-Dec-2021
* Author: Admin
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "F28x_Project.h"
#include "F2837xD_device.h"
#include "F2837xD_Examples.h"
#include "device.h"
#include "driverlib.h"
#define BUFFER_SIZE 128
Uint16 rdata_pointA; // Used for checking the received data
char rdataA[BUFFER_SIZE]; // Received data for SCI-A
void UART_GPIO_init();
void SCI_A_init();
__interrupt void sciaTxISR(void);
__interrupt void sciaRxISR(void);
void main(void)
{
Device_init();
Device_initGPIO();
DINT;
UART_GPIO_init();
SCI_A_init();
Interrupt_initModule();
Interrupt_initVectorTable();
IER = 0x0000;
IFR = 0x0000;
// Map the ISR to the wake interrupt.
//
Interrupt_register(INT_SCIA_TX, sciaTxISR);
Interrupt_register(INT_SCIA_RX, sciaRxISR);
Interrupt_enable(INT_SCIA_RX);
Interrupt_enable(INT_SCIA_TX);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
EINT;
while(1)
{
// SCI_writeCharArray(SCIA_BASE, (uint16_t *)"sci communication interrupt mode\r\n", sizeof("sci communication interrupt mode\r\n"));
// DEVICE_DELAY_US(1000000);
}
}
void UART_GPIO_init()
{
//SCIB -> SCI0 Pinmux
GPIO_setPinConfig(GPIO_43_SCIRXDA);
GPIO_setPinConfig(GPIO_42_SCITXDA);
}
void SCI_A_init()
{
SCI_performSoftwareReset(SCIA_BASE);
//
// Configure SCIA for echoback.
//
SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 9600, (SCI_CONFIG_WLEN_8 |
SCI_CONFIG_STOP_ONE |
SCI_CONFIG_PAR_NONE));
SCI_resetChannels(SCIA_BASE);
SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
SCI_enableModule(SCIA_BASE);
SCI_performSoftwareReset(SCIA_BASE);
//
// Enable the TXRDY and RXRDY interrupts.
//
SCI_enableInterrupt(SCIA_BASE, SCI_INT_TXRDY | SCI_INT_RXRDY_BRKDT);
#ifdef AUTOBAUD
//
// Perform an autobaud lock.
// SCI expects an 'a' or 'A' to lock the baud rate.
//
SCI_lockAutobaud(SCIA_BASE);
#endif
}
__interrupt void
sciaTxISR(void)
{
//
// Disable the TXRDY interrupt.
//
SCI_disableInterrupt(SCIA_BASE, SCI_INT_TXRDY);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}
__interrupt void
sciaRxISR(void)
{
rdataA[rdata_pointA]=SciaRegs.SCIRXBUF.all;
rdata_pointA++;
if(rdata_pointA>=BUFFER_SIZE)
rdata_pointA = 0;
if(rdataA[rdata_pointA-1]=='\n')
{
SCI_writeCharArray(SCIA_BASE, (uint16_t*)rdataA, rdata_pointA);
memset(rdataA,'\0',128);
rdata_pointA = 0;
}
PieCtrlRegs.PIEACK.all|=0x100; // Issue PIE ack
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP9);
}