我创建了一个系统,该系统将从车辆读取 CANBUS 数据并将其无线传输到“基站”。到目前为止,我的代码的工作原理是它通过数据线将东西发送到 xbee,xbee 将其发送到接收模块,除了它唯一发送的东西是 FF 和 FE,无论我要求它发送什么. 任何帮助是极大的赞赏。
主程序
/**
Section: Included Files
*/
#include "mcc_generated_files/clock.h"
#include "mcc_generated_files/dma.h"
#include "mcc_generated_files/ecan1.h"
#include "mcc_generated_files/interrupt_manager.h"
#include "mcc_generated_files/mcc.h"
#include "mcc_generated_files/pin_manager.h"
#include "mcc_generated_files/reset.h"
#include "mcc_generated_files/reset_types.h"
#include "mcc_generated_files/system.h"
#include "mcc_generated_files/system_types.h"
#include "mcc_generated_files/traps.h"
#include "mcc_generated_files/uart1.h"
#include "mcc_generated_files/watchdog.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
void ms_delay (int N)
{
T1CON = 0x08030;
int delay = N * 62.5; // 1 Milisecond => .001 / (256 * (1/16,000,000)) = 62.5
TMR1 = 0;
while (TMR1 < delay);
}
int main (void)
{
PIN_MANAGER_Initialize();
CLOCK_Initialize();
INTERRUPT_Initialize();
//DMA_Initialize();
UART1_Initialize();
ECAN1_Initialize();
//INTERRUPT_GlobalEnable();
while(1)
{
UART1_Write("A");
ms_delay(2);
UART1_Write("C");
ms_delay(2);
UART1_Write('S');
ms_delay(2);
}
}
/**
End of File
*/
UART1.c
Section: Included Files
*/
#include "uart1.h"
/**
Section: UART1 APIs
*/
void UART1_Initialize(void)
{
/**
Set the UART1 module to the options selected in the user interface.
Make sure to set LAT bit corresponding to TxPin as high before UART initialization
*/
// STSEL 1; IREN disabled; PDSEL 8N; UARTEN enabled; RTSMD disabled; USIDL disabled; WAKE disabled; ABAUD disabled; LPBACK disabled; BRGH enabled; URXINV disabled; UEN TX_RX;
// Data Bits = 8; Parity = None; Stop Bits = 1;
U1MODE = (0x8008 & ~(1<<15)); // disabling UARTEN bit
// UTXISEL0 TX_ONE_CHAR; UTXINV disabled; OERR NO_ERROR_cleared; URXISEL RX_ONE_CHAR; UTXBRK COMPLETED; UTXEN disabled; ADDEN disabled;
U1STA = 0x00;
// BaudRate = 2560.164; Frequency = 40000000 Hz; BRG 3905;
U1BRG = 0x19;
U1MODEbits.UARTEN = 1; // enabling UARTEN bit
U1STAbits.UTXEN = 1;
}
uint8_t UART1_Read(void)
{
while(!(U1STAbits.URXDA == 1))
{
}
if ((U1STAbits.OERR == 1))
{
U1STAbits.OERR = 0;
}
return U1RXREG;
}
void UART1_Write(uint8_t txData)
{
while(U1STAbits.UTXBF)
{
}
U1TXREG = txData; // Write the data byte to the USART.
}
uint16_t UART1_StatusGet (void)
{
return U1STA;
}
/*int __attribute__((__section__(".libc.write"))) write(int handle, void *buffer, unsigned int len) {
int i;
while(U1STAbits.TRMT == 0);
for (i = len; i; --i)
{
while(U1STAbits.TRMT == 0);
U1TXREG = *(char*)buffer++;
}
return(len);
}*/
预期结果:从一个模块向另一个模块重复发送 YES 实际结果:repretedly 发送 FF FE