Я пытаюсь настроить базовую последовательную связь между dsPIC33FJ64GP802 и терминалом и ПК с помощью модуля UART.Однако UART не передает более одного символа.Я использую MPLAB-X (V 5.05).Я также использую Snap Debugger для программирования dsPic.Я пытаюсь изобразить ошибку в моем коде.Я попытался изменить сам dsPic и модуль Bluetooth, а также.Это не работает.Я не знаю, пропускаю ли я какие-то биты.
// FBS
#pragma config BWRP = WRPROTECT_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_FLASH // Boot Segment Program Flash Code Protection (No Boot program Flash segment)
#pragma config RBS = NO_RAM // Boot Segment RAM Protection (No Boot RAM)
// FSS
#pragma config SWRP = WRPROTECT_OFF // Secure Segment Program Write Protect (Secure segment may be written)
#pragma config SSS = NO_FLASH // Secure Segment Program Flash Code Protection (No Secure Segment)
#pragma config RSS = NO_RAM // Secure Segment Data RAM Protection (No Secure RAM)
// FGS
#pragma config GWRP = OFF // General Code Segment Write Protect (User program memory is not write-protected)
#pragma config GSS = OFF // General Segment Code Protection (User program memory is not code-protected)
// FOSCSEL
#pragma config FNOSC = LPRCDIVN // Oscillator Mode (Internal Fast RC (FRC) with divide by N)
#pragma config IESO = ON // Internal External Switch Over Mode (Start-up device with FRC, then automatically switch to user-selected oscillator source when ready)
// FOSC
#pragma config POSCMD = NONE // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = OFF // OSC2 Pin Function (OSC2 pin has clock out function)
#pragma config IOL1WAY = ON // Peripheral Pin Select Configuration (Allow Only One Re-configuration)
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Both Clock Switching and Fail-Safe Clock Monitor are disabled)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config WDTPRE = PR128 // WDT Prescaler (1:128)
#pragma config WINDIS = OFF // Watchdog Timer Window (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = ON // Watchdog Timer Enable (Watchdog timer always enabled)
// FPOR
#pragma config FPWRT = PWR128 // POR Timer Value (128ms)
#pragma config ALTI2C = OFF // Alternate I2C pins (I2C mapped to SDA1/SCL1 pins)
// FICD
#pragma config ICS = PGD1 // Comm Channel Select (Communicate on PGC1/EMUC1 and PGD1/EMUD1)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG is Disabled)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
#include <stdbool.h>
#include "stdio.h"
#include <string.h>
//delay in milliseconds
void delay_milliseconds(long double milliSecond)
{
milliSecond = (milliSecond * 147);
long double i;
for(i = 0; i<milliSecond;i++);
}
/*
Main application
*/
void UART1_setup(void)
{
U1BRG = 25;
U1MODE = 0;
U1MODEbits.UEN = 0;
U1MODEbits.UARTEN = 1; //enable the module
U1STAbits.UTXEN = 1; //enable transmissiond
U1MODEbits.BRGH = 0;
U1STAbits.UTXISEL1 = 1;
U1STAbits.UTXISEL0 = 0;
U1STAbits.UTXBF = 0;
U1STAbits.URXDA = 1;
U1STAbits.OERR = 0;
U1STAbits.FERR = 0;
U1STAbits.PERR = 0;
INTCON1bits.NSTDIS = 0;
IFS0bits.U1RXIF = 0;
IEC0bits.U1RXIE = 1;
IPC2bits.U1RXIP = 7;
}
char UART1_Read(void)
{
while(!(U1STAbits.URXDA == 1))
{
}
if ((U1STAbits.OERR == 1))
{
U1STAbits.OERR = 0;
}
return U1RXREG;
}
void UART1_Write(char txData)
{
while(U1STAbits.UTXBF == 1)
{
}
U1TXREG = txData; // Write the data byte to the USART.
}
void printString(char *data)
{
int len = strlen(data);
int i =0;
for( i = 0; i<len; i++)
{
char txData = *(data + i);
UART1_Write(txData);
}
}
void __attribute__((interrupt, no_auto_psv)) _U1RXInterrupt(void)
{
//Clear receive interrupt flag
IFS0bits.U1RXIF = 0;
}
uint8_t data[2];
void pinSetup(void)
{
//set directions
TRISBbits.TRISB11 = 0; //TX
TRISBbits.TRISB10 = 1; //Rx
//***************************************************************************&&
__builtin_write_OSCCONL(OSCCON & 0xbf); // unlock PPS
RPINR18bits.U1RXR = 0x000B; //RB11->UART1:U1RX
RPOR5bits.RP10R = 0x0003; //RB10->UART1:U1TX
//RPINR0bits.INT1R = 0x0005; //RB5->EXT_INT:INT1
__builtin_write_OSCCONL(OSCCON | 0x40); // lock PPS
//////////////////**********************************************************************&&&&&&&&
}
int main(void)
{
pinSetup();
I2C1_init();
UART1_setup();
while(true)
{
UART1_Write('A');
}
}