19 June,2012
The core of the board is arm-cortex-m3,
Now the task is to send the commands and messages to the board. We
will send the commands and messages to the board and the board will
decode the commands and messages and accordingly give instructions to
the actuators and peripherals to behave in a certain manner. Our computer is connected to the
microcontroller via serial port. Hence we have to decipher the UART
communication of the Board. For this I took the manual of LPC1768
and studied How the serial communication can be done on the Board.
Before proceeding further we need to understand that there are two
programs required, one on microcontroller to handle the serial port
of microcontroller and one on computer, using that program on
computer we can send data to the microcontroller, here i mean to say
that for setting the various parameters of the serial port of the
computer for example baud rate , parity, stop bits so that we can
synchronize both the ports (our computer and microcontroller serial
ports).
For testing purposes like to send the
characters on the serial port of the comptuer i used hyperterminal
(windows utility), minicom (In linux). These are the client programs
but in future we ourselves have to write this program (Client
Program for serial Communication).
First We will connect our
microcontroller to the Computer via serial port. Mainly the communication between computer and
microcontroller is done via interrupt. Whenever there is
character available on the serial port of the microcontroller, an
interrupt is occured and those interrput can be handled using the
UARTIRQHandler Routine. When interrupt occurts it jumps on the
UARTIRQHandler routine and executes it. In LPC1768 four kinds of
interrupts can be occured which are handled in the same irq handler
using if else if statements.
Structure of the interrupt handler in
LPC1768
void UART0_IRQHandler (void)
(Interrupt Handler Routine)
{
1. if ( IIRValue == IIR_RLS ) /*
Receive Line Status */
{
if ( LSRValue &
(LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
{
}
if ( LSRValue & LSR_RDR ) /*
Receive Data Ready */
{
}
}
2. else if ( IIRValue == IIR_RDA
) /* Receive Data Available */
{
}
3. else if ( IIRValue == IIR_CTI
) /* Character timeout indicator */
{
}
4. else if ( IIRValue == IIR_THRE
) /* THRE, transmit holding register empty */
{
}
}
As above in the structure shown in the
bold fonts with numbered as 1,2,3, and 4 these are the 4 interrupts
can be occured.
The first one is Receive Line Status
interrupt, it is a highest priority interrupt and it occurs in
one of the following conditions-
(a) OVERRUN ERROR (OE)
(b) PARITY ERROR (PE)
(c) FRAMING ERROR (FE)
(d) BREAK INTERRUPT (BI )
the interrupt will execute within this
particular block of code.
if ( LSRValue &
(LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
{
}
The second most priority interruput is
2 receive data available when rx fifo reaches on trigger level, in
this case cpu can read the data block from the receive buffer
register.
In the priority order third level
interrupt is CTI (Character Timeout Interrupt)
and the lowest priority interrupt
occurs when transmit holding register is empty (transmit holding
register handles the data which is transmitted)
Hence followed by this i managed to
control the LED'S of the microcontroller using the keyboard of my
computer. This was something like this, when i pressed suppose 's'
character of keyboard of my computer (client program for sending the
character on the serial port was minicom) using minicom i sent the
character 's' on the serial port of my computer and serial port of my
computer is connected to the serial port of the microcontroller, so
microcontroller receive the character 's' and it invokes the
interrupt handler routine and in interrupt handler routine i compared
the character received with the character 's' if it is true i
switched on the specific led of the microcontroller.
In this way i managed to control the
LED of the microcontroller using the keyboard of my computer.
-------------------------------------------------------------------------------------------------------------------------------------