Problema UART pic24F08KA101

Hola,
estoy utilizando el pic p24F08KA101 y quiero comunicar un pic con otro mediante el UART. He realizado un codigo para un pic que envia un dato de 8 bit con paridad a otro pic.Mi codigo es mu simple, en el que consigo que el pic envie el dato pero el segundo pic no puede leer el dato. El dato se va enviando todo el tiempo. Utilizo una salida digital para ver a traves de una led cuando realiza el codigo correctamente¿puede ser que tenga algun fallo para configurar las interrupciones o al inicializar la uart?
Estos son los codigos de cada uno de los pic, tanto del emisor como del receptor.

EMISOR

#include <p24fxxxx.h>
#include <ports.h>
#include <p24F08KA101.h>
#include <uart.h>
_FOSCSEL(FNOSC_FRC);
_FOSC(OSCIOFNC_ON&FCKSM_CSDCMD&POSCMOD_NONE);
_FPOR(MCLRE_OFF&BORV_LPBOR&PWRTEN_OFF);
_FDS(DSWDTEN_OFF& DSBOREN_OFF&RTCOSC_LPRC);

unsigned int k=1;

int main(void){
IO_Init();
UART_Init();
while(1){
while(U1STAbits.UTXBF); //wait while TX is full
U1TXREG =0b10101010;
}
}
//////////////////////////////////////////////////////
void UART_Init(void)
{
U1BRG=51; //Set Baudrate Para 8MHz a 9600 baudios con BRGH=0

U1MODE = 0x0000; //no parity, 1 STOP bit
_U1TXIF=0;
IEC0bits.U1TXIE = 1; //Enable Transmit Interrupt
U1STAbits.UTXISEL0=0;
U1STAbits.UTXISEL1=1;
U1MODE = 0x8000;
U1STAbits.UTXEN = 1; //Enable Transmit
U1STAbits.UTXBF=0;
}
/////////////////////////////////////////////

void IO_Init(void)
{
TRISAbits.TRISA2 = 0;
}
/////////////////////////////////////////////
/////////////////////////////////////////////
//***** Interrupt Service routine for UART1 Transmission *******
void __attribute__ ((interrupt,no_auto_psv)) _U1TXInterrupt(void)
{
PORTAbits.RA2= 1; //salida led encendia
for(k=0;k<60000;k++); //delay
PORTAbits.RA2= 0; //salida led apagada
for(k=0;k<60000;k++); //delay
_U1TXIF=0;
}

______________________________________________________________________
RECEPTOR

#include <p24fxxxx.h>
#include <ports.h>
#include <p24F08KA101.h>
#include <uart.h>
_FOSCSEL(FNOSC_FRC);
_FOSC(OSCIOFNC_ON&FCKSM_CSDCMD&POSCMOD_NONE);
_FPOR(MCLRE_OFF&BORV_LPBOR&PWRTEN_OFF);
_FDS(DSWDTEN_OFF& DSBOREN_OFF&RTCOSC_LPRC);

unsigned int uart1buf = 0b00000000;
unsigned int k=1;
int main(void){
IO_Init();
UART_Init();

PORTAbits.RA2= 1; //salida led encendida
while(1){
}
}
//////////////////////////////////////////////////////////
void UART_Init(void)
{
U1BRG=51; //Set Baudrate
IPC2bits.U1RXIP2 = 1; //Set Uart RX Interrupt Priority
IPC2bits.U1RXIP1 = 0;
IPC2bits.U1RXIP0 = 0;
U1MODE = 0x0000; //no parity, 1 STOP bit

_U1RXIF=0;
IEC0bits.U1RXIE = 1; //Enable Receive Interrupt

U1STAbits.URXISEL=0x11;
U1MODE = 0x8000; //no parity, 1 STOP bit
U1STAbits.URXDA = 0; // el buffer esta libre.

}

/////////////////////////////////////////////
void IO_Init(void)
{
TRISAbits.TRISA2 = 0;

//******* Interrupt Service routine for UART1 reception ********
void __attribute__ ((interrupt,no_auto_psv)) _U1RXInterrupt(void)
{

uart1buf= U1RXREG;

PORTAbits.RA2= 0; //salida led apagada
_U1RXIF=0;

}


Espero que alguien pueda echarme una mano.
 
Ahora con CCS 4.104 podés trabajar perfectamente con los PIC24 y eso que vos planteas es mucho más facil hacerlo con ese compilador.
 
Atrás
Arriba