How can ARM7 LPC2132 RS485 send and receive data, please hel
Posted: Thu Nov 28, 2019 10:08 pm
The program is a routine. Is there anything else I need to set? RS485 connected to serial assistant, no data
#include <Lpc213x.H>
#define UART_BPS 9600
#define FPCLK 12000000
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void DelayNS (uint32 dly)
{
uint32 i;
for (; dly> 0; dly--)
for (i = 0; i <50000; i ++);
}
void UART1_init (void)
{
uint16 Fdiv;
U1LCR = 0x83;
Fdiv = (FPCLK / 16) / UART_BPS;
U1DLM = Fdiv / 256;
U1DLL = Fdiv% 256;
U1LCR = 0x03;
}
void UART1_SendByte (uint8 data)
{
U1THR = data;
while ((U1LSR & 0x40) == 0);
}
void UART1_SendStr (uint8 const * str)
{
while (1)
{
UART1_SendByte (* str ++);
if (* str == '\ 0')
break;
}
}
int main (void)
{
PINSEL0 = 0x50000;
UART1_init ();
while (1)
{
UART1_SendStr ("welcome! \ N");
DelayNS (100);
}
return (0);
}
#include <Lpc213x.H>
#define UART_BPS 9600
#define FPCLK 12000000
typedef unsigned int uint32;
typedef unsigned short uint16;
typedef unsigned char uint8;
void DelayNS (uint32 dly)
{
uint32 i;
for (; dly> 0; dly--)
for (i = 0; i <50000; i ++);
}
void UART1_init (void)
{
uint16 Fdiv;
U1LCR = 0x83;
Fdiv = (FPCLK / 16) / UART_BPS;
U1DLM = Fdiv / 256;
U1DLL = Fdiv% 256;
U1LCR = 0x03;
}
void UART1_SendByte (uint8 data)
{
U1THR = data;
while ((U1LSR & 0x40) == 0);
}
void UART1_SendStr (uint8 const * str)
{
while (1)
{
UART1_SendByte (* str ++);
if (* str == '\ 0')
break;
}
}
int main (void)
{
PINSEL0 = 0x50000;
UART1_init ();
while (1)
{
UART1_SendStr ("welcome! \ N");
DelayNS (100);
}
return (0);
}