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.

UARTIntHandler

Hi,

I'm trying to power a Kent Scientific Syringe Pump using the TM4C microcontroller and the kentec lcd, however, when i clicked the start button from the lcd, the syringe pump did not react to the start button being pressed. Is there anything wrong with my UART config?

PS: I am able to build and debug the codes.

Thanks,

Eisen

Here's the code:

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_uart.h"
#include "inc/hw_ints.h"
#include "driverlib/debug.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "driverlib/interrupt.h"
#include "utils/uartstdio.h"
#include "grlib/grlib.h"
#include "driverlib/timer.h"
#include "Kentec320x240x16_ssd2119_8bit.h"
#include "driverlib/gpio.h"
#include "grlib/widget.h"
#include "touch.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"

#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
//Error routine


bool g_sStartButtonState = false;
bool g_sStopButtonState = false;

//Declaration
tContext g_sContext;
tRectangle g_sRect;

extern tCanvasWidget g_sBackground;
extern tCanvasWidget g_sHeader;
extern tPushButtonWidget g_sStartButton;
extern tPushButtonWidget g_sStopButton;

void StopButtonPress(tWidget *pWidget);
void StartButtonPress(tWidget *pWidget);
void ClearScreen(void);
void LCD_Init(void);
void StartUpScreen(void);
void PumpConfig(void);
void UARTConfig (void);


uint32_t RunOrStp_ui32Flags = 0;
//Initial state of syringe pump


uint32_t ui32TargetVolume = 20;
uint32_t ui32InfusionRate_default = 0;
uint32_t ui32DiameterSyringe = 20;
//uint32_t Speed_ui32Flags = 0; initial state of syringe pump

//-------------------------Widgets Settings--------------------------------
tCanvasWidget g_sBackground = CanvasStruct(0, 0, &g_sHeader, //psParent, psNext, psChild,
&g_sKentec320x240x16_SSD2119, 0, 0, 320, 240, //psDisplay, i32X, i32Y, i32Width, i32Height,
(CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT), //ui32Style-bit sets,
ClrWhite, ClrWhite, ClrBlack, //ui32FillColor, ui32OutlineColor, ui32TextColor,
&g_sFontCmtt14, 0, 0, 0); //psFont, pcText, pui8Image, pfnOnPaint

tCanvasWidget g_sHeader = CanvasStruct(&g_sBackground, &g_sStartButton, 0, //psParent, psNext, psChild,
&g_sKentec320x240x16_SSD2119, 3, 20, 320, 32, //psDisplay, i32X, i32Y, i32Width, i32Height,
(CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT), //ui32Style-bit sets,
ClrWhite, ClrWhite, ClrBlack, //ui32FillColor, ui32OutlineColor, ui32TextColor,
&g_sFontCmtt20, "Syringe Pump Settings", 0, 0); //psFont, pcText, pui8Image, pfnOnPaint

tPushButtonWidget g_sStartButton = RectangularButtonStruct(&g_sBackground, &g_sStopButton, 0, //psParent, psNext, psChild
&g_sKentec320x240x16_SSD2119, 30, 150, 180, 75, //PsDisplay, i32X, i32Y, i32Width, i32height,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |PB_STYLE_FILL), //ui32Style-bit sets
ClrLawnGreen, ClrYellow, ClrBlack, ClrBlack, //ui32FillColor, ui32PressFillColor, ui32OutlineColor, ui32TextColor,
&g_sFontCmtt18, "Start", 0, 0, //psFont, pcText, pui8Image, pui8PressImage,
0, 0, StartButtonPress); //ui16AutoRepeatDelay, ui16AutoRepeatRate, pfnOnClick

tPushButtonWidget g_sStopButton = RectangularButtonStruct(&g_sBackground, 0, 0, //psParent, psNext, psChild,
&g_sKentec320x240x16_SSD2119, 240, 150, 70, 40, //psDisplay, i32X, i32Y, i32Width, i32Height,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |PB_STYLE_FILL), //ui32Style-bit sets
ClrRed, ClrYellow, ClrBlack, ClrBlack, //ui32FillColor, ui32PressFillColor, ui32OutlineColor, ui32TextColor,
&g_sFontCmtt14, "Stop", 0, 0, //psFont, pcText, pui8Image, pfnOnPaint
0, 0, 0); //ui16AutoRepeatDelay, ui16AutoRepeatRate, pfnOnClick
//-----------------------------------------------------------------------------
void LCD_Init(void){
Kentec320x240x16_SSD2119Init(); //initialise color LCD 320x240 pix,16 colors (subroutine)
TouchScreenInit();
GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);
ClearScreen();

GrContextForegroundSet(&g_sContext, ClrBlack);
GrContextFontSet(&g_sContext, &g_sFontCmtt14);

TouchScreenCallbackSet(WidgetPointerMessage);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sHeader);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sStartButton);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sStopButton);
WidgetPaint(WIDGET_ROOT);
}
//-----------------------------------------------------------------------------
void StartUpScreen(void){
//Start-Up Screen
g_sRect.i16XMin = 0;
g_sRect.i16YMin = 0;
g_sRect.i16XMax = 318;
g_sRect.i16YMax = 238;
GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);
GrContextForegroundSet(&g_sContext, ClrBlack);
GrContextFontSet(&g_sContext, &g_sFontCmss22b);
GrStringDraw(&g_sContext, "Automatic", -1, 110, 10, 0); //string, x, y, 0
GrStringDraw(&g_sContext, "Blood Pressure", -1, 86, 40, 0);
GrStringDraw(&g_sContext, "Control System", -1, 83, 70, 0);
GrStringDraw(&g_sContext, "Eisen and Samuel", -1, 72, 110, 0);
GrStringDraw(&g_sContext, "Advisor:", -1, 124, 140, 0);
GrStringDraw(&g_sContext, "Dr Zhu Kuanyi", -1, 89, 170, 0);
GrStringDraw(&g_sContext, "Mr Foo Wan Juang", -1, 63, 200, 0);
GrContextForegroundSet(&g_sContext, ClrWhite);
GrRectDraw(&g_sContext, &g_sRect);
GrFlush(&g_sContext);
SysCtlDelay(25000000);
ClearScreen();
WidgetPaint(WIDGET_ROOT);
}
//-----------------------------------------------------------------------------
void ClearScreen(void){
g_sRect.i16XMin = 0;
g_sRect.i16YMin = 0;
g_sRect.i16XMax = 319;
g_sRect.i16YMax = 239;
GrContextForegroundSet(&g_sContext, ClrWhite);
GrRectFill(&g_sContext, &g_sRect);
GrFlush(&g_sContext);
}
//-----------------------------------------------------------------------------
void StartButtonPress(tWidget *pWidget){
g_sStartButtonState = !g_sStartButtonState; //change StartButtonState to True


ROM_SysCtlDelay(900000);

UARTprintf("%s\r", "RUN");
ROM_SysCtlDelay(900000);

UARTprintf("%s, %d\r", "MLM", 5);
ROM_SysCtlDelay(100000);

// g_sStartButtonState = !g_sStartButtonState; // Change back false


//WidgetPaint(WIDGET_ROOT);
}
//-----------------------------------------------------------------------------
void StopButtonPress(tWidget *pWidget){
g_sStopButtonState = !g_sStopButtonState; //change StopButtonState to True
UARTprintf("%s\r", "STP");
//ROM_SysCtlDelay(900000);
//WidgetPaint(WIDGET_ROOT);
}

//-----------------------------------------------------------------------------
//UART and pins config

void UARTConfig (void)
{

ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);


ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);


ROM_GPIOPinConfigure(GPIO_PB0_U1RX);
ROM_GPIOPinConfigure(GPIO_PB1_U1TX);
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);


UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);


UARTStdioConfig(1, 9600, 16000000);
}

//-----------------------------------------------------------------------------
//Pump config

void PumpConfig(void)
{
//
// Transmission to the pump terminating with a "CR" character, the pump enters remote mode.
//
UARTprintf("%s\r\n", "CR");
ROM_SysCtlDelay(100000);

//
// Set syringe diameter, units are mm.
//
UARTprintf("%s, %d\r\n", "MMD", ui32DiameterSyringe);
ROM_SysCtlDelay(100000);

//
// Rate is set to zero after MMD command.
//
UARTprintf("%s, %d\r\n", "MLM", ui32InfusionRate_default);
ROM_SysCtlDelay(100000);

}

//-----------------------------------------------------------------------------

void UARTIntHandler(void)
{
uint32_t ui32Status;
ui32Status = UARTIntStatus(UART1_BASE, true); //get interrupt status
UARTIntClear(UART1_BASE, ui32Status); //clear the asserted interrupts
while(UARTCharsAvail(UART1_BASE)) //loop while there are chars
{
UARTCharPutNonBlocking(UART1_BASE, UARTCharGetNonBlocking(UART1_BASE)); //echo character
}
}

//-----------------------------------------------------------------------------

void main(void){
SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

//
// Initialize the UART.
//
UARTConfig();

UARTIntHandler();

//
// Syringe Pump Configuration.
//
//PumpConfig();

LCD_Init();
StartUpScreen();

while(1)
{
WidgetMessageQueueProcess();
}
}