Other Parts Discussed in Thread: EK-TM4C129EXL
Dear Sir,
I have a problem for receiving data form uart0 in ek-tm4c129exl board. I want to receive a data stream one by one like (one start bit, 17,03,00,04,45,77,one stop bit.). But I don't understand logic. How can I receive data from uart0 FIFO. Please help me. My code is given below--
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
//#include "utils/uartstdio.h"
//****************************************************************************
//
// System clock rate in Hz.
//
//****************************************************************************
uint32_t g_ui32SysClock;
unsigned char MY_SLAVE_ID =17u;
#define MaxFrameIndex 255u
#define fc3_HoldingRegMax 125u
#define fc3_HoldingRegOffset 40001u
volatile unsigned char ResponseFrameSize;
volatile unsigned char data_in[MaxFrameIndex+1];
volatile unsigned int DataPos;
//Holding Register Array
static unsigned int HoldingRegisters[] = {
24288, 30717, 52317, 58320, 53844, 7596, 50869, 64892, 58209, 15124, //0-9
38131, 16852, 62343, 25973, 11963, 49434, 31745, 48278, 50955, 50027, //10-19
62940, 38520, 51144, 54693, 60394, 14244, 62402, 62647, 65457, 56695, //20-29
40971, 29608, 37659, 60486, 3321, 769, 52458, 61584, 55023, 61523, //30-39
50744, 51336, 3649, 48678, 29801, 43147, 1325, 32661, 49277, 32353, //40-49
48858, 41522, 32167, 13748, 24501, 2375, 6957, 45371, 53417, 34799, //50-59
51057, 3290, 13510, 48962, 65080, 22597, 38672, 14315, 48621, 49290, //60-69
30178, 1793, 13119, 54566, 1570, 31355, 1754, 21305, 5750, 25520, //70-79
23688, 54689, 64511, 17349, 33911, 31220, 64245, 17176, 43586, 30999, //80-89
12761, 42338, 62682, 7424, 6981, 36057, 63189, 4897, 52723, 61279, //90-99
};
unsigned short CRC16 (volatile unsigned char *puchMsg, unsigned short usDataLen );
unsigned int MBRegisterCount(void);
void AppendDatatoMBRegister(unsigned int StAddr,unsigned int count, unsigned int *inreg, volatile unsigned char *outreg);
unsigned int MBStartAddress(void);
void MBSendData(unsigned char count);
void AppendCRCtoMBRegister(unsigned char packtop);
void MBException(unsigned char exceptionCode);
void MBProcessRegisters(unsigned char fcCode);
//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void UARTIntHandler(void)
{
uint32_t ui32Status;
uint8_t i;
//
// Get the interrrupt status.
//
ui32Status = MAP_UARTIntStatus(UART0_BASE, true);
//
// Clear the asserted interrupts.
//
MAP_UARTIntClear(UART0_BASE, ui32Status);
//
// Loop while there are characters in the receive FIFO.
//
while(MAP_UARTCharsAvail(UART0_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
for(i=0;i<11;i++)
{
data_in[10] = (uint8_t)MAP_UARTCharGetNonBlocking(UART0_BASE);
i++;
}
if((DataPos>=8u)&(data_in[0]=MY_SLAVE_ID))
{
DataPos=0;
switch(data_in[1])
{
case 0x03:
{
MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
}
break;
default:
{
MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
}
break;
}
}
}
/*MAP_UARTCharPutNonBlocking(UART0_BASE,
a );
MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);*/
// MAP_UARTCharPutNonBlocking(UART0_BASE,
// data );
//
// Blink the LED to show a character transfer is occuring.
//
// MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
//SysCtlDelay(g_ui32SysClock / (1000 * 3));
//
// Turn off the LED
//
// else MAP_GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
}
//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
MAP_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
}
}
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
MY_SLAVE_ID=17u;
//
// Run from the PLL at 120 MHz.
// Note: SYSCTL_CFG_VCO_240 is a new setting provided in TivaWare 2.2.x and
// later to better reflect the actual VCO speed due to SYSCTL#22.
//
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_240), 120000000);
//
// Enable the GPIO port that is used for the on-board LED.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
//
// Enable the GPIO pins for the LED (PN0).
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
//
// Enable the peripherals used by this example.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Enable processor interrupts.
//
MAP_IntMasterEnable();
//
// Set GPIO A0 and A1 as UART pins.
//
MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
MAP_UARTConfigSetExpClk(UART0_BASE, g_ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//
// Enable the UART interrupt.
//
MAP_IntEnable(INT_UART0);
MAP_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
//
// Prompt for text to be entered.
//
//UARTSend((uint8_t *)"\033[2JEnter text: ", 16);
//
// Loop forever echoing data through the UART.
//
while(1)
{
}
}
Regards
Imtiaj