embpic
Advanced Member level 3
- Joined
- May 29, 2013
- Messages
- 742
- Helped
- 80
- Reputation
- 160
- Reaction score
- 77
- Trophy points
- 1,308
- Location
- india
- Activity points
- 5,213
#include<lpc214x.h>
void uart0(void)__irq;
void init_uart0(void);
void Initialize(void);
void tx(unsigned char *);
unsigned int aa,r_data;
int main(void)
{
Initialize();
tx("Hello WOrld This is LPC2148");
// tx(r_data);
while(1);
}
void Initialize(void)
{
VPBDIV = 0x00;
PINSEL0 = 0x00000005;
PINSEL1 = 0X00000000;
PINSEL2 = 0X00000000;
IO0SET = (1<<19);
IO0DIR = 0xfffffff0; //61
aa = 0;
init_uart0();
}
void init_uart0(void)
{
U0LCR = 0x83;
U0DLL = 0x61;
U0DLM = 0x00;
U0FDR = 0x00000010;
U0IER = 0x00000007;
// U0FCR = 0x06;
U0LCR &= 0x03;
U0FCR = 0x01;
U0RBR = 0x00;
U0THR = 0x00;
VICIntEnable = 0x00000040;
VICIntSelect = 0x00000000;
VICVectCntl0 = 0x00000026;
VICVectAddr0 = (unsigned long)uart0;
}
void uart0(void)__irq
{
// IO0SET = (1<<16+aa);
// aa++;
IO0PIN ^=(1<<19);
if(U0IIR & 0x40)
r_data = U0RBR;
VICVectAddr = 0x00;
}
void tx(unsigned char *stn)
{
do
{
while(!(U0LSR & 0x20));
U0THR = *stn++;
}
while(*stn!='\0');
}
#include<lpc214x.h>
void initialize(void);
void tx_stn(unsigned char *);
#define XTAL 12000000
#define PCLK (XTAL/4)
void init_uart(void)
{
U0RBR = 0x00;
U0THR = 0x00;
U0LCR = 0X83;
U0DLL = 0x00000061;
U0DLM = 0x00;
U0FDR = 0x00000010;
U0IER = 0x07;
U0LCR &= 0X03;
// U0FCR = 0x06;
U0FCR = 0x01;
}
int main()
{
initialize();
tx_stn("Hello World how are you today !!!");
while(1);
}
void initialize(void)
{
PINSEL0 = 0x00000005; // Enable UART0 Rx and Tx pins
init_uart();
}
void tx_stn(unsigned char *str)
{
while(*str!='\0')
{
while(U0LSR & 0x20 == 0);
U0THR = *str++;
}
}
#include<lpc214x.h>
void initialize(void);
void tx_stn(unsigned char *);
#define XTAL 12000000
#define PCLK (XTAL/4)
void init_uart(void)
{
U0RBR = 0x00;
U0THR = 0x00;
U0LCR = 0X83;
U0DLL = 0x00000061;
U0DLM = 0x00;
U0FDR = 0x00000010;
U0IER = 0x07;
U0LCR &= 0X03;
// U0FCR = 0x06;
U0FCR = 0x01;
}
int main()
{
initialize();
tx_stn("Hello World how are you today !!!");
while(1);
}
void initialize(void)
{
PINSEL0 = 0x00000005; // Enable UART0 Rx and Tx pins
init_uart();
}
void tx_stn(unsigned char *str)
{
while(*str!='\0')
{
while(U0LSR & 0x20 == 0);
U0THR = *str++;
}
}
i am using Keil compiler and arm7 lpc2148
- - - Updated - - -
what does FIFO actually do in rx and tx.
problems are:
1. i was trying to set baud rate at 9600 but get fixed at 496
2. 16 character get skipped due use of FIFO (i think).
#include<lpc214x.h>
void uart_init(void);
void init(void);
void tx_stn(unsigned char *);
void rx_stn(void);
int main()
{
init();
tx_stn("Hello World how are you today2");
// rx_stn();
while(1);
{
}
}
void init(void)
{
VPBDIV = 0x00;
PINSEL0 = 0x00000005;
uart_init();
}
void uart_init(void)
{
U0LCR = 0x83;
U0DLL = 0x61;
U0DLM = 0x00;
U0LCR &= 0x03;
// U0FCR = 0x01;
}
void tx_stn(unsigned char *stn)
{
do
{
U0THR = *stn++;
while(U0LSR & 0x40==0);
}while(*stn!='\0');
}
void rx_stn(void)
{
unsigned char aa;
do
{
aa = U0RBR;
if(aa=='a')
{
IO0SET = (1<<18);
}
}while(aa!='b');
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 #include<lpc21xx.h> void uart_init(void); void init(void); void tx_stn(unsigned char *); void rx_stn(void); int main() { init(); while(1) { tx_stn("Hello World how are you today2"); rx_stn(); } } void init(void) { PLLCON = 0x00; //disable PLL PLLFEED = 0xAA; PLLFEED = 0x55; VPBDIV = 0x02; //pclk = CCLK/4 and CCLK = Fosc PINSEL0 = 0x00000005; uart_init(); } void uart_init(void) { U0LCR = 0x83; U0DLL = 39; U0DLM = 0x00; U0LCR = 0x03; } void tx_stn(unsigned char *stn) { do { U0THR = *stn++; while((U0LSR & 0x40) == 0); //Here is your fault }while(*stn!='\0'); } void rx_stn(void) { unsigned char a; do{ while(!(U0LSR & 01)); a = U0RBR; if(a=='a') IO0SET = (1<<18); }while(a!='z'); }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 #include<lpc21xx.h> void uart_init(void); void init(void); void tx_stn(unsigned char *); int main() { init(); tx_stn("Hello World how are you today2"); while(1) { } } void init(void) { PLLCON = 0x00; //disable PLL PLLFEED = 0xAA; PLLFEED = 0x55; VPBDIV = 0x02; //pclk = CCLK/2 and CCLK = Fosc PINSEL0 = 0x00000005; uart_init(); } void uart_init(void) { U0LCR = 0x83; U0DLL = 39; U0DLM = 0x00; U0LCR = 0x03; U0FCR = 0x07; // Extra line } void tx_stn(unsigned char *stn) { int i; do{ for( i = 0; i < 16 && *stn != '\0' ; i++) U0THR = *stn++; // Put 16 datas on the buffer while( ! (U0LSR & 0x40) ); // Wait for all of them to transmit } (*stn != '\0' ) // do this until all data transmitted }
Go and look at the #3 That has the ISR function..thank you sir for providing example for FIFO. and how to add interrupt for transmitter for sending data rather than waiting for data to send. i had tried and i have written for rx.
is there required delay while sending data OR
use this method use instead of interrupt.
void sio_irq (void) __irq
{
volatile char IIR;
IIR = U1IIR;
if ( (IIR & 0x0E) == 0x02 )
if ( i <= size )
{
U1THR = tx[i%TXSIZE]; //here also u are putting data in Tx buffer
i++;
}
VICVectAddr = 0; /* Acknowledge Interrupt */
}
void transmit(const char *str,int siz)
{
int j;
U1IER &= ~2;
if(i >= size)
{
for(j = 0; j < siz; j++)
tx[j%TXSIZE] = str[j];
i = 0;
size = siz;
U1THR = tx[i%TXSIZE]; // here also u r putting data
i++;
}
else
{
for(j = 0; j < siz; j++)
tx[(j+size)%TXSIZE] = str[j];
size = siz + size;
}
U1IER |= 2;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?