Hi friends,
I am facing a strange issue. I am trying to serially communicate between two microcontrollers(LPC2148) and in vain.
1)I ve used one board for transmitting 'A' continuously @9600,8bits,No pairity,1stop bit. It works well with P.C-Hyperterminal.
2)I ve used another board to receive the data sent by 1 and display it in LCD. it never works.
I ve tried both ways: connecting Rxd,Txd,Gnd appropriately, and using Max 232 on both sides.
My doubt is : does hyperterminal recieve data differently?
I ve called a function rec, which waits and receives a byte of data, which is returned.
for your reference:
unsigned char rec()
{
unsigned char p;
while ((U0LSR&0x01)!=1);
p=U0RBR;
return p;
}
I ve also included my C code. don't mind it, I am a shabby fellow
but do help me. Am equally dumb.
I am facing a strange issue. I am trying to serially communicate between two microcontrollers(LPC2148) and in vain.
1)I ve used one board for transmitting 'A' continuously @9600,8bits,No pairity,1stop bit. It works well with P.C-Hyperterminal.
2)I ve used another board to receive the data sent by 1 and display it in LCD. it never works.
I ve tried both ways: connecting Rxd,Txd,Gnd appropriately, and using Max 232 on both sides.
My doubt is : does hyperterminal recieve data differently?
I ve called a function rec, which waits and receives a byte of data, which is returned.
for your reference:
unsigned char rec()
{
unsigned char p;
while ((U0LSR&0x01)!=1);
p=U0RBR;
return p;
}
I ve also included my C code. don't mind it, I am a shabby fellow
Rich (BB code):
#include<lpc214x.h>
#define enhi IO0SET=(1<<18)
#define rshi IO0SET=(1<<16)
#define rwlo IO0CLR=(1<<17)
#define enlo IO0CLR=(1<<18)
#define rslo IO0CLR=(1<<16)
void init() //UART0 initialization
{
U0LCR=0x83;
U0DLL=0x61;
U0DLM=0x00;
U0LCR=0x03;
}
unsigned char rec() //recieves a byte of data
{
unsigned char p;
while ((U0LSR&0x01)!=1);
p=U0RBR;
return p;
}
void delay(int msec)
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<60000;j++);
}
void cmd(unsigned int text) //LCD command sending fn
{
unsigned int cmdhi=(text&0xF0)<<15;
unsigned int cmdlow=(text&0x0F)<<19;
rwlo;
rslo;
IO0PIN&=0xFF07FFFF;
IO0PIN|=cmdhi;
enhi;
delay(1);
enlo;
//delay(20);
IO0PIN&=0xFF07FFFF;
IO0PIN|=cmdlow;
enhi;
delay(1);
enlo;
}
void data(unsigned int dat) //LCD data sending fn
{
unsigned int dathi=(dat&0xF0)<<15;
unsigned int datlow=(dat&0x0F)<<19;
rwlo;
rshi;
//delay(20);
IO0PIN&=0xFF87FFFF;
IO0PIN|=dathi;
enhi;
delay(1);
enlo;
//delay(20);
IO0PIN&=0xFF87FFFF;
IO0PIN|=datlow;
enhi;
delay(1);
enlo;
}
void word(unsigned char *word)
{
while(*word!='\0')
{
data(*word);
word++;
}
}
int main()
{
PINSEL0=0x00000005;
PINSEL1 = 0x00000000;
PINSEL2 = 0x00000000;
IO0DIR|=(1<<16)|(1<<17)|(1<<18)|(1<<19)|(1<<20)|(1<<21)|(1<<22);
init();
cmd(0x20);
cmd(0x28);
cmd(0x0C);
cmd(0x06);
cmd(0x01);
cmd(0x80);
while(1)
{
data(rec());
}
}