Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

reception problems on UART dspic30f

Status
Not open for further replies.
Joined
Feb 8, 2022
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
13
hello I have been working with the dspic30f4011, but I have a problem receiving data from the uart, I need to receive a String but I have not been able to, as after the "OERR" buffer overflow flag is raised and I clear the flag it does not take the data, the manufacturer's datasheet says to save the data before clearing the, however, I do but it only receives me 5 characters.
C:
// _XTAL_FREQ = INTERNAL OF 7.5MHz PLL_16 = 120MHz
// FCY= _XTAL_FREQ /4
#define FOSC 7500000 //7.5MHz Define la frecuencia de oscilacion del cristal.
#define PLL 16 //SI hay PLL, 7.5MHZ X 16=120MHz
#define FCY FOSC*PLL/4 // Frecuencia de cada instruccion (4 seciones de reloj) 30MHz
// 'C' source line config statements
#include <p30F4011.h>
//DEFINIR MACROS (del archivo p30f4011 en los archivos del compilador)
_FOSC( FRC_PLL16 & CSW_FSCM_OFF) //Frecuencia de Oscilacion
_FWDT( WDT_OFF ) //Whatchdog timer
_FBORPOR( PWRT_16 & BORV20 & MCLR_EN ) //Reinicio
_FGS( CODE_PROT_OFF ) //Seguridad


void init_UART1(void) {
    U1MODEbits.UARTEN = 1; // se activa el modulo UART
    U1MODEbits.USIDL = 0; // operacion continua en IDLMODE
    U1MODEbits.ALTIO = 1; // se escoge el uart alternativoU1ATX y U1ARX
    U1MODEbits.WAKE = 0; // despertar desactivado
    U1MODEbits.LPBACK = 0; // modo de retorno desactivado
    U1MODEbits.ABAUD = 0; // aurot baudiaje desactivado
    U1MODEbits.PDSEL = 0; // 8bits sin paridad
    U1MODEbits.STSEL = 0; // y bit de stop
    // configuracion de los baud rate
    // mirar pag 506-507
    U1BRG = 32; //57600
    //interrupciones
    IPC2bits.U1RXIP = 5; //prioridad
    IFS0bits.U1RXIF = 0; //se limpia la bandera de interrupcion
    IEC0bits.U1RXIE = 0; // sin interrupciones

    U1STAbits.UTXISEL = 1;
    U1STAbits.UTXBRK = 0;
    U1STAbits.UTXEN = 1; // se activa el pin de tramsmision de datos U1ATX
    U1STAbits.UTXBF = 0;
    U1STAbits.TRMT = 0; // el registro de transmision esta vacio
    U1STAbits.URXISEL = 0; // interrupcion cuando hay un caracter en el buffer
    U1STAbits.RIDLE = 0;
    U1STAbits.ADDEN = 0; // modo de deteccion desabilidado
    U1STAbits.PERR = 0; //sin error de paridad
    U1STAbits.PERR = 0; //Sin errores de encuadre
    U1STAbits.OERR = 0; // el buffer esta limpio de recepcion
    U1STAbits.URXDA = 0; //no hay datos para recibir
}

void Read_LoRA(void) {
    int i_aux = 0;
    // Clear the overflow bit to recieve data
    while (U1STAbits.URXDA == 1) {
        if ((U1STAbits.OERR == 1)) {
            buffer_reception[i_aux] = U1RXREG;
            buffer_reception[i_aux + 1] = U1RXREG;
            buffer_reception[i_aux + 2] = U1RXREG;
            buffer_reception[i_aux + 3] = U1RXREG;
            buffer_reception[i_aux + 4] = U1RXREG;
            i_aux += 5;
            U1STAbits.OERR = 0;
        }

        if (U1STAbits.FERR == 1) {
            U1STAbits.FERR = 0;
            continue;
        }
        if (U1STAbits.PERR == 1) {
            U1STAbits.PERR = 0;
            continue;
        }

        buffer_reception[i_aux] = U1RXREG;
        i_aux++;
    }
    LATEbits.LATE8 = 1;
    __delay_ms(20);
    LATEbits.LATE8 = 0;
    __delay_ms(20);
    UART1_Send_Command("dato:");
    UART1_Send_Command(buffer_reception);
    UART1_Write(0x0D); // CR; retorno de carro"enter"
    UART1_Write(0x0A); // NF; salto del linea
}


int main(void) {
    TRISEbits.TRISE8 = 0;
    TRISCbits.TRISC15 = 0;
    TRISDbits.TRISD1 = 1;

    init_UART1();

    while (1) {
        //if available data in buffer
        if (U1STAbits.URXDA == 1) {
            Read_LoRA();
        }
        LATCbits.LATC15 = 1;
        __delay_ms(100);
        LATCbits.LATC15 = 0;
        __delay_ms(100);

    }
    return 0;
}
 

I don't use that device but normally you receive when the OERR is NOT set and you reset the USART if it IS set because it means an overflow has occurred.

Brian.
 

Hi,

* I don´t see where "buffer_reception" is defined in type and size.

* in "void Read_LoRA(void)" you just read 5 bytes. So you can´t expect to be more bytes in buffer_reception

Klaus
 

We don't know how much characters are send in a burst, also if GPIO C15 has any effect on the sender. It's most likely that the 4 character deep UART FIFO is overrun during one of the delay cycles. Instead of trying to design a special receive routine, use the standard solution, an interrupt driven receive function.
 

Hi,

* I don´t see where "buffer_reception" is defined in type and size.

* in "void Read_LoRA(void)" you just read 5 bytes. So you can´t expect to be more bytes in buffer_reception

Klaus
you are right, I didn't add the reception_buffer variable to the code in my question, but it has a size of 40, I correct it now,
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top