doubts on ARM TUTORIAL : uart
Sat Jul 09 2011, 02:04 pm
hi
m trying to setup Uart1 of lpc2148 to receive byte using interrupt
i have written d code for it
when a byte is rxd interupt occurs isr function is executed correctly but only 1 time.
when anohter byte is sent execution doesnt enter isr. m sure there might b a problem with my code but m not able to find 1
code
main.c:
#include "lcd.h"
#include "test.h"
#include "serial.h"
int main (void)
{
init_lcd();
Test_Lcd();
Uart1_Init();
Uart1_Tx('A');
while (1)
{
}
}
serial.c:
#include <LPC21xx.H>
#include "lcd.h"
#define TEMT (1<<6)
//****************************************************************
// Function name : Uart1_Tx
// Parameters : unsigned char Tx_Data
// Return Parameter : None
// Description : Transmits the Tx_Data to Uart1
//
//****************************************************************
void Uart1_Tx(unsigned char Tx_Data)
{
while(!(U1LSR & TEMT));
U1THR = Tx_Data;
}
//****************************************************************
// Function name : Uart1_Irq
// Parameters : None
// Return Parameter : None
// Description : Uart1 Rx ISR
//****************************************************************
void Uart1_Irq()
{
unsigned char Data;
lcd_putstring(0," Uart1 IRQ ");
Data = U1RBR;
Uart1_Tx(Data);
VICVectAddr = 0; //end of interrupt
lcd_putstring(1," done ");
}
//****************************************************************
// Function name : Uart1_Init
// Parameters : None
// Return Parameter : None
// Description : Initializes Uart1 for 8 data bit, 1 stop bit
// no parity and 9600 Baud rate*
//****************************************************************
void Uart1_Init()
{
PINSEL0 = 0x00050000; //init pins for uart1 rxd1 & txd1
U1LCR = 0x83; //8bit data, 1 stop bit, no parity
U1DLL = 97; //9600 baud rate
//U1DLL = 24; //38400 baud rate
U1LCR = 0x03; //dlab disable
U1IER = 0x01; //Uart1 RBR interrupt enable
VICProtection = 0; //Diable protection
VICIntSelect &= 0xffffff7f; // select Uart1 Interrupt as IRQ
VICVectAddr0 = (unsigned int)Uart1_Irq;//Assigning isr Addr
VICVectCntl0 = 0x20 | 7;
VICIntEnable |= 0x00000080; //enable uart1 interrupt
}
plz help find missing code
thanks n regards
naqsh
m trying to setup Uart1 of lpc2148 to receive byte using interrupt
i have written d code for it
when a byte is rxd interupt occurs isr function is executed correctly but only 1 time.
when anohter byte is sent execution doesnt enter isr. m sure there might b a problem with my code but m not able to find 1
code
main.c:
#include "lcd.h"
#include "test.h"
#include "serial.h"
int main (void)
{
init_lcd();
Test_Lcd();
Uart1_Init();
Uart1_Tx('A');
while (1)
{
}
}
serial.c:
#include <LPC21xx.H>
#include "lcd.h"
#define TEMT (1<<6)
//****************************************************************
// Function name : Uart1_Tx
// Parameters : unsigned char Tx_Data
// Return Parameter : None
// Description : Transmits the Tx_Data to Uart1
//
//****************************************************************
void Uart1_Tx(unsigned char Tx_Data)
{
while(!(U1LSR & TEMT));
U1THR = Tx_Data;
}
//****************************************************************
// Function name : Uart1_Irq
// Parameters : None
// Return Parameter : None
// Description : Uart1 Rx ISR
//****************************************************************
void Uart1_Irq()
{
unsigned char Data;
lcd_putstring(0," Uart1 IRQ ");
Data = U1RBR;
Uart1_Tx(Data);
VICVectAddr = 0; //end of interrupt
lcd_putstring(1," done ");
}
//****************************************************************
// Function name : Uart1_Init
// Parameters : None
// Return Parameter : None
// Description : Initializes Uart1 for 8 data bit, 1 stop bit
// no parity and 9600 Baud rate*
//****************************************************************
void Uart1_Init()
{
PINSEL0 = 0x00050000; //init pins for uart1 rxd1 & txd1
U1LCR = 0x83; //8bit data, 1 stop bit, no parity
U1DLL = 97; //9600 baud rate
//U1DLL = 24; //38400 baud rate
U1LCR = 0x03; //dlab disable
U1IER = 0x01; //Uart1 RBR interrupt enable
VICProtection = 0; //Diable protection
VICIntSelect &= 0xffffff7f; // select Uart1 Interrupt as IRQ
VICVectAddr0 = (unsigned int)Uart1_Irq;//Assigning isr Addr
VICVectCntl0 = 0x20 | 7;
VICIntEnable |= 0x00000080; //enable uart1 interrupt
}
plz help find missing code
thanks n regards
naqsh
Sat Jul 09 2011, 03:16 pm
sorry
i found d issue
i had missed adding __irq to void Uart1_Irq()
ie Uart1_Irq() __irq{
so plz ignore
thanks anyways
regards
naqsh
i found d issue
i had missed adding __irq to void Uart1_Irq()
ie Uart1_Irq() __irq{
so plz ignore
thanks anyways
regards
naqsh
Thu Jan 12 2012, 12:33 pm
Excellent tutorial @Shyam. I am a newbie to ARM .Things seem clearer to me.. I could not find a continuation link to the above thread. pls post if any.
link for the thread:
www.8051projects.net/forum-t4311-10.html
link for the thread:
www.8051projects.net/forum-t4311-10.html
[ Edited Thu Jan 12 2012, 12:35 pm ]
Wed Jan 18 2012, 06:55 pm
I could not find a continuation link to the above thread. pls post if any.
Pawankumar
Which link are you talkin about? Please let me know I will look into it.
Mon Jan 23 2012, 09:35 pm
hi Ajay,
the thread is : ARM tutorial : UART
link for the thread is: http://www.8051projects.net/forum-t4311-0.html
its a great tutorial. shyam has closed the thread without discussing the following as proposed
4.sending a byte of data.
5. receiving a byte of data.
6. using in interrupt.
7.difference between polled and interrupt mode
or am I lost somewhere?
P.S: am not able to use the hyperlink option excuse me.
the thread is : ARM tutorial : UART
link for the thread is: http://www.8051projects.net/forum-t4311-0.html
its a great tutorial. shyam has closed the thread without discussing the following as proposed
4.sending a byte of data.
5. receiving a byte of data.
6. using in interrupt.
7.difference between polled and interrupt mode
or am I lost somewhere?
P.S: am not able to use the hyperlink option excuse me.
Tue Jan 24 2012, 10:09 am
hi can any1 plz guide me to setup printf function to work with uart using stdio.h?
i did some trial n error but didnt find success. so waiting for reply
regards
naqsh
i did some trial n error but didnt find success. so waiting for reply
regards
naqsh
Tue Jan 24 2012, 09:45 pm
@naqsh.salim
take a look at this...
http://www.keil.com/support/man/docs/gsac/gsac_lowlevelroutinesarm.htm
take a look at this...
http://www.keil.com/support/man/docs/gsac/gsac_lowlevelroutinesarm.htm
Tue Jan 31 2012, 10:39 pm
please help . I am trying to interface GPS module with LPC2148. I have written a code to get data from GPS through UART1 and send it to hyperterminal through UART0. This code does not work. where am i wrong?
#include<lpc214x.h> void inituart1() //initializes both UARTS at 9600 baud { U1LCR=0x83; U1DLL=0x61; U1DLM=0x00; U1LCR=0x03; U0LCR=0x83; U0DLL=0x61; U0DLM=0x00; U0LCR=0x03; } void send(unsigned char a) //sends a byte through U0 { U0THR=a; while(U0LSR!=0x60); } void senduart1(unsigned char a) //sends a byte through U1 { U1THR=a; while(U1LSR!=0x60); } unsigned char recuart1() // recieves a byte from U1 { unsigned char p; while ((U1LSR&0x01)!=1); p=U1RBR; return p; } unsigned char rec() // recieves a byte from U0 { unsigned char p; while ((U0LSR&0x01)!=1); p=U0RBR; return p; } int main() { PINSEL0=0x00050005; //initialized U0 and U1 as UART and not GPIO PINSEL1 = 0x00000000; PINSEL2 = 0x00000000; inituart1(); while(1) { send(recuart1()); } }
[ Edited Tue Jan 31 2012, 10:45 pm ]
Powered by e107 Forum System