При выполнении цикла(в коде указано) происходит reset через произвольное количество итераций(в пределах 50). Прошу помочь решить проблему. Сильно не пинайте, в программировании микроконтроллеров полный нуб.
#include <xc.h>
#include "p33ep64mc202.h"
// DSPIC33EP64MC202 Configuration Bit Settings
// 'C' source line config statements
// FICD
#pragma config ICS = PGD1 // ICD Communication Channel Select bits (Communicate on PGEC1 and PGED1)
#pragma config JTAGEN = OFF // JTAG Enable bit (JTAG is disabled)
// FPOR
#pragma config ALTI2C1 = OFF // Alternate I2C1 pins (I2C1 mapped to SDA1/SCL1 pins)
#pragma config ALTI2C2 = OFF // Alternate I2C2 pins (I2C2 mapped to SDA2/SCL2 pins)
#pragma config WDTWIN = WIN25 // Watchdog Window Select bits (WDT Window is 25% of WDT period)
// FOSC
#pragma config POSCMD = NONE // Primary Oscillator Mode Select bits (Primary Oscillator disabled)
#pragma config OSCIOFNC = 0 // OSC2 Pin Function bit (OSC2 is clock output)
#pragma config IOL1WAY = OFF // Peripheral pin select configuration (Allow only one reconfiguration)
#pragma config FCKSM = CSECMD // Clock Switching Mode bits (Both Clock switchingswitching is enabled, Fail-safe Clock Monitor are disabled)
// FOSCSEL
#pragma config FNOSC = FRC // Oscillator Source Selection (Internal Fast RC (FRC))
#pragma config PWMLOCK = ON // PWM Lock Enable bit (Certain PWM registers may only be written after key sequence)
#pragma config IESO = ON // Two-speed Oscillator Start-up Enable bit (Start up device with FRC, then switch to user-selected oscillator source)
// FGS
#pragma config GWRP = OFF // General Segment Write-Protect bit (General Segment may be written)
#pragma config GCP = OFF // General Segment Code-Protect bit (General Segment Code protect is Disabled)
// FWDT
#pragma config WDTPOST = PS32768 // Watchdog Timer Postscaler bits (1:32,768)
#pragma config WDTPRE = PR128 // Watchdog Timer Prescaler bit (1:128)
#pragma config PLLKEN = OFF // PLL Lock Enable bit (Clock switch to PLL source will wait until the PLL lock signal is valid.)
#pragma config WINDIS = OFF // Watchdog Timer Window Enable bit (Watchdog Timer in Non-Window mode)
#pragma config FWDTEN = 0 // Watchdog Timer Enable bit (Watchdog timer enabled/disabled by user software)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define Fcy 40000000
#define BAUDRATE 9600
#define BRGVAL ((Fcy/BAUDRATE)/16)-1
void __attribute__ ( (interrupt, no_auto_psv) ) _U1RXInterrupt( void )
{
//LATA = U1RXREG;
//U1TXREG = LATA;
IFS0bits.U1RXIF = 0;
return;
}
void __attribute__ ( (interrupt, no_auto_psv) ) _U1TXInterrupt( void )
{
IFS0bits.U1TXIF = 0;
return;
}
void WriteUART1(char data)
{
while (U1STAbits.UTXBF); //wait until TXREG is available
U1TXREG = data; //send one byte
}
int main() {
//Disable WDT
RCONbits.SWDTEN = 0;
// Configure PLL prescaler, PLL postscaler, PLL divisor
PLLFBD = 41; // M=43
CLKDIVbits.PLLPOST = 0; // N2=2
CLKDIVbits.PLLPRE = 0; // N1=2
// Initiate Clock Switch to FRC oscillator with PLL (NOSC=0b001)
__builtin_write_OSCCONH(0x01);
__builtin_write_OSCCONL(OSCCON | 0x01);
// Wait for Clock switch to occur
while (OSCCONbits.COSC!= 0b001);
// Wait for PLL to lock
while (OSCCONbits.LOCK!= 1);
// configure U1MODE
U1MODEbits.UARTEN = 0; // Bit15 TX, RX DISABLED, ENABLE at end of func
//U1MODEbits.notimplemented;// Bit10
U1MODEbits.UEN = 0; // Bits8,9 TX,RX enabled, CTS,RTS not
U1MODEbits.ABAUD = 0; // Bit5 No Autobaud (would require sending '55')
U1MODEbits.BRGH = 0; // Bit3 16 clocks per bit period
U1MODEbits.PDSEL = 0; // Bits1,2 8bit, No Parity
U1MODEbits.STSEL = 0; // Bit0 One Stop Bit
// Load a value into Baud Rate Generator.
U1BRG = BRGVAL; // 20Mhz osc, 9600 Baud
// Load all values in for U1STA SFR
U1STAbits.UTXISEL1 = 0; //Bit15 Int when Char is transferred (1/2 config!)
U1STAbits.UTXISEL0 = 0; //Bit13 Other half of Bit15
U1STAbits.UTXBRK = 0; //Bit11 Disabled
U1STAbits.UTXEN = 0; //Bit10 TX pins controlled by periph
U1STAbits.URXISEL = 0; //Bits6,7 Int. on character recieved
IPC7 = 0x4400; // Mid Range Interrupt Priority level, no urgent reason
IFS0bits.U1TXIF = 0; // Clear the Transmit Interrupt Flag
IEC0bits.U1TXIE = 0; // Enable Transmit Interrupts
IFS0bits.U1RXIF = 0; // Clear the Recieve Interrupt Flag
IEC0bits.U1RXIE = 0; // Enable Recieve Interrupts
//UART pins
RPOR0bits.RP20R = 1; // RP20 as U1TX
_U1RXR = 0x36; // RPI25 as U1RX
//Enable UART
U1MODEbits.UARTEN = 1; // And turn the peripheral on
U1STAbits.UTXEN = 1;
//
ANSELA = 0;
INTCON2bits.GIE = 0;
//Отправка символа
WriteUART1('a');
//
if (U1STAbits.OERR == 1){
U1STAbits.OERR = 0;
}
//
while (1) {
//ТУТ ПРОИСХОДИТ RESET
}
return 0;
}