Other Parts Discussed in Thread: CC2530, Z-STACK
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
Thread 中讨论的其他器件:CC2530、 Z-STACK大家好、
我正在使用 CC2530直接配置相关寄存器来构建 UART 项目。
以下是我的代码:
在我的 UART 库中:
void clock_setting()
{
CLKCONCMD &= 0x80;
while (CLKCONSTA!= CLKCONCMD);
}
void uartInitBudate (unsigned char uartBaudM、unsigned char uartBaudE)
{
U0BAUD = uartBaudM;
U0GCR =(U0GCR &~
~0x1F)| uartBaudE;}void uartInit (Uartpara= 0x0UART_UART= 0x80+ UART= UART0UART0UART= UART0UART0UART0UART0UART_UART0UART= 0xUART0UART0UART0_UART0UART0_UART0UART
U0UCR =(U0UCR&~0x02)|(UART_PARA_CONFIG.STOP << 1);
U0UCR =(U0UCR&~0x04)|(UART_PARA_CONFIG.SPB << 2);
U0UCR=(U0UCR&~0x08)|(UART_PARA_CONFIG.CR<
0x20)
|
(U0UCR< U0UCCR = U0U0UCCR = U0U0UCR<~U0UCCR = 0x20)|(U0U0UCCR = U0UCCR = U0U0U0UCCR = U0U0U0UCCR = U20+ UCCR = U0U0UCCR = U0U0UCCR = U0U0U0UCCR = U0U0U0UCCR = U0U0U0UCCR = U0U0U0UCCR =~)(U20+ U0U0UCCR =~~
否则
{
P2DIR &= 0x00;
P2DIR |= 0x40;
U1CSR |= 0x80;
U1UCR =(U1UCR&~0x01)| UART_PARA_CONFIG.START;
U1UCR =(U1UCR&~
~
~
~0x02)|(UART_PART_CONFIG.STOP << 1);U1UCR=UCR=0x4 (U1UCR_UCR=UCR.UCR=UCR=UCR.UCR.UCR=UCR.UCR.04)|(U1UCR=UCR.UCR=UCR.UCR.UCR.UCR.UCR=UCR=U1UCR=UCR.UCR.UCR.UCR=UCR.UCR.UCR.UCR.UCR.UCR.UCR.UCR=
U1UCR =(U1UCR&~0x20)|(UART_PARA_CONFIG.d9 << 5);
U1UCR =(U1UCR&~0x40)|(UART_PARAL_CONFIG.flow << 6);
U1GCR =(U1GCR&~
~
~0x20)|(UART_PART_CONFIG.ORDER < 0x3C)|无符号端口数= 0x1UARTSEL = 0x3 (UARTSEL = 0x3);UART0)= 0x1UARTSEL = 0x3C (UARTSEL = 0x3 = 0x3 (UARTFP= 0x3C);0)= 0x3 (如果是无符号端口1)= 0x3 (UART0)= 0x3 (UARTSEL = 0x3);无符号端口=
否则
{
PERCFG &=~0x02;
P0SEL |= 0x3C;
P1SEL &=~0xF0;
}
否则
{
(uartNumber = 0)
{
/* PERCFG.U0CFG = 1 */
PERCFG |= 0x01;
P1SEL |= 0x3C;
P0SEL &=~
~0xF0;}否则{PERCFG |= 0x3C |= 0xSEL;
= 0x3C;}= 0xSEL = 0x3C;}
}
char uart0Receive_char (void)
{
char data = 0;
URX0IF = 0;
U0CSR |= 0x40;
while (!URX0IF);
data = U0DBUF;
URX0IF = 0;
返回数据;
}
void uart0Send (char* uartTxBuf)
{
unsigned short i;
UTX0IF = 0;
for (i = 0;uartTxBuf[i]!= 0;i++)
{
U0DBUF = uartTxBuf[i];
while (!UTX0IF
= 0)
;}}UartX0IF = 0
在我的 void main()中:
char * receive_buf;
unsigned char len = 0; UART_Parameter x = { UART_0 、 LOW_LEVEL_START_BIT、 HIGH_LEVEL_STOP_BIT、 One_stop_bit 、 奇偶校验使能 、 transfer_9_bit 、 奇偶校验 、 flow_control_disable、 LSB_FIRST }; Clock_setting (); uartInitBudate (BAUD_M_9600_32MHz、BAUD_E_9600_32MHz); uartInit (x); uartSelectPort (Alter_1、UART_0); while (1) { while (uart0Receive_char ()!= 0) Receive_buf[len++]= uart0Receive_char (); Receive_buf[len]=0; uart0Send (receive_buf); }
我在 Hercules 平台上运行、使用函数 uart0Receive_char ()按字符发送字符串。 我想通过将其发送回塑料板来检查接收是否正常。
不幸的是、它似乎不起作用。 不过、如果我只是向塑料板发送文本、传输效果会更完美。
感谢您的关注。