Hi,
I've the same pb few month aog. I do this and it's work fine. I hope this
exemple help you.
Regards,
Sebastien Jacquemard
#define EN_TXD1 0x00010000
#define EN_RXD1 0x00040000
#define SENS 0x00000400 //P0.10 = Rs485 sens
#define Txd 1 // RS485 : mode transmission
#define Rxd 0 // RS485 : mode r\ufffdception
#define TXD_BREAK 0x40 // Set TXD break
void init_rs485()
{
IOSET0=SENS; //SENS=TXD
PINSEL0 |= EN_RXD1 | EN_TXD1; // Enable RxD1 and TxD1
U1LCR = 0x8B; // 8 bits, Odd parity, 1 Stop bit
U1DLL = Baud187500;
U1LCR &= 0x7F; // DLAB = 0
}
void trasnmit_rs485(uchar *p)
{
uchar n;
uchar pause;
IOSET0=SENS; //SENS=Txd --> rs485 in tx mode
U1LCR|=TXD_BREAK; //break on txd1 line
tempo(110); //tempo 90usec
U1LCR&=~TXD_BREAK; //clear break
n=*p++;
do{
while (!(U1LSR & 0x20)) watchdog(); //wait tx buffer empty
U1THR = *p++;
} while (--n);
//wait buffer empty before swith in rx mode
while ((U1LSR & 0x60)!=0x60) watchdog();
IOCLR0=SENS; //SENS=Rxd --> rs485 in rx mode}
}
uchar receive_rs485(uchar *p)
{
uchar n;
uint fin;
IOCLR0=SENS; //SENS=Rxd --> rs485 in rx mode
n=*p; // number of char to receive
fin=100000;
do{
do{
if (!fin)
{
IOSET0=SENS; //SENS=Txd --> rs485 in tx mode
return(0);
}
fin--;
watchdog();
} while(!(U1LSR & 0x01)); //wait char
*p++=U1RBR; // store char
} while(--n);
IOSET0=SENS; //SENS=Txd --> rs485 in tx mode
return(1);
}Message
Re: [lpc2000] RS485
2005-09-19 by Sebastien Jacquemard
Attachments
- No local attachments were found for this message.