Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

C18, PIC18F24J11 and 2 EUSART

Status
Not open for further replies.

soniavit

New Member
Hi everyone!

I'm trying to use the 2 EUSART of a pic18f24j11.
It's my first time with C18 and double EUSART, so I need some help...

It seems that the EUSART2 receiver doesn't work (the PIR3.RC2IF never goes to 1).

Do you have any ideas?
Thank you so much for your help
Sonia


My updated code:

Code:
#include "p18f24j11.h"
#include "usart.h"
#include "delays.h"
#pragma config WDTEN = OFF
#pragma config STVREN = OFF
#pragma config XINST = OFF
#pragma config CP0 = OFF
#pragma config OSC = HS
#pragma config T1DIG = OFF
#pragma config LPT1OSC = OFF
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config DSBOREN = OFF
#pragma config DSWDTEN = OFF
#pragma config IOL1WAY = OFF
void Delay1ms(void)
{
Delay1KTCYx(5);
}
void Delay_ms(int count)
{
int i;
for(i=0;i<count;i++) Delay1ms();
}

void main (void)
{
int dato;
TRISAbits.TRISA0 = 1;
TRISAbits.TRISA1 = 0;
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
//***************************************************
// CODICE ASSEMBLY PER PIN MAPPING
//***************************************************
_asm
MOVLB 0x0E     // unlock registri   
MOVLW 0x55     // .....................
MOVWF EECON2, 0    // ..
MOVLW 0xAA     // ..
MOVWF EECON2, 0    // ..
BCF PPSCON, 0, BANKED  // .....................
MOVLW 0x00     // RX2 -> RP0
MOVWF RPINR16, BANKED  // .....................
MOVLW 0x05     // TX2 -> RP1
MOVWF RPOR1, BANKED   // .....................
MOVLW 0x55     // lock registri
MOVWF EECON2, 0    // ..
MOVLW 0xAA     // ..
MOVWF EECON2, 0    // ..
BSF PPSCON, 0, BANKED  // .....................
_endasm
//***************************************************
Open1USART  ( USART_TX_INT_OFF 
     & USART_RX_INT_OFF
   & USART_ADDEN_OFF
   & USART_ASYNCH_MODE 
   & USART_EIGHT_BIT 
   & USART_CONT_RX 
   & USART_BRGH_HIGH, 129);

Open2USART  ( USART_TX_INT_OFF 
   & USART_RX_INT_OFF 
   & USART_ADDEN_OFF
   & USART_ASYNCH_MODE 
   & USART_EIGHT_BIT 
   & USART_CONT_RX 
   & USART_BRGH_HIGH, 129);
Delay_ms(200);
while (1)
{
 if(DataRdy1USART())
 {
  dato= Read1USART();
  Write2USART(dato);
  LATCbits.LATC1 ^= 1; //DEBUG
 }
 if(PIR3bits.RC2IF)
 {
  dato= Read2USART();
  Write1USART(dato);
  LATCbits.LATC0 ^= 1; //DEBUG
 }
} 
}
 
Last edited:
Why aren't you using,
Code:
    if(DataRdy2USART())
I have no idea how these library routines work but you need to either use the hardware or use the library. Don't mix them up.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top