Estoy trabajando en un microcontrolador pic24fj128ga202 con módulo L80 y M95. aquí el módulo L80 conectado con uart2 y el módulo M95 conectado con uart3. ahora uart1 funciona normalmente, pero uart2 y uart3 no funcionan (es decir) no obtuve datos de gps y gprs. main.c
#include "p24FJ128GA202.h"
#include <stdio.h>
#define led PORTAbits.RA2
#include "UART.h"
#include "IOCONFIG.h"
int main()
{
GSMPwrkey=1;
init_processor();
uartx1( uart2rx());
return 0;
}
UART.h
#include<stdio.h>
/* transmit a character in uart1 */
void uartx1(char in_c)
{
while(U1STAbits.UTXBF == 1);
U1TXREG = in_c;
}
/* transmit a character in uart1 */
void uartx2(char in_c)
{
while(U2STAbits.UTXBF == 1);
U2TXREG = in_c;
}
/* transmit a character in uart3 */
void uartx3( char in_c)
{
while(U3STAbits.UTXBF == 1);
U3TXREG = in_c;
}
/* Receive a character in uart1 */
char uart1rx()
{
char c;
while(U1STAbits.URXDA == 0);
c = U1RXREG;
return c;
}
/* Receive a character in uart2 */
char uart2rx()
{
char c;
while(U2STAbits.URXDA == 0);
c =U2RXREG;
return c;
}
/* Receive a character in uart3 */
char uart3rx()
{
char c;
while(U3STAbits.URXDA == 0);
return U3RXREG;
return c;
}
/* transmit a string in uart1 */
void uartstr1( char *s)
{
while(*s!='#include "p24FJ128GA202.h"
#include <stdio.h>
#define led PORTAbits.RA2
#include "UART.h"
#include "IOCONFIG.h"
int main()
{
GSMPwrkey=1;
init_processor();
uartx1( uart2rx());
return 0;
}
UART.h
#include<stdio.h>
/* transmit a character in uart1 */
void uartx1(char in_c)
{
while(U1STAbits.UTXBF == 1);
U1TXREG = in_c;
}
/* transmit a character in uart1 */
void uartx2(char in_c)
{
while(U2STAbits.UTXBF == 1);
U2TXREG = in_c;
}
/* transmit a character in uart3 */
void uartx3( char in_c)
{
while(U3STAbits.UTXBF == 1);
U3TXREG = in_c;
}
/* Receive a character in uart1 */
char uart1rx()
{
char c;
while(U1STAbits.URXDA == 0);
c = U1RXREG;
return c;
}
/* Receive a character in uart2 */
char uart2rx()
{
char c;
while(U2STAbits.URXDA == 0);
c =U2RXREG;
return c;
}
/* Receive a character in uart3 */
char uart3rx()
{
char c;
while(U3STAbits.URXDA == 0);
return U3RXREG;
return c;
}
/* transmit a string in uart1 */
void uartstr1( char *s)
{
while(*s!='%pre%')
{
uartx1(*s);
s++;
}
}
/* transmit a string in uart3 */
void uartstr3( char *s)
{
while(*s!='%pre%')
{
uartx3(*s);
s++;
}
}
IOCONFIG.h
#include<stdio.h>
#include<stdint.h>
#define GSMPwrkey PORTBbits.RB12
#define GPSreset PORTBbits.RB15
void Timer1DelaymsInit(void);
void Delayms(uint16_t delay);
void init_Processor(void);
void Timer1DelaymsInit(void)
{
T1CONbits.TCKPS = 0; //Timer1 Prescale Select bit
T1CONbits.TCS = 0; //Timer1 Clock source(FOSC/2)
PR1 = 3760;
TMR1 = 0;
IEC0bits.T1IE = 0;
T1CONbits.TON = 1;
}
void Delayms(uint16_t delay)
{
while(delay>0)
{
TMR1 = 0;
IEC0bits.T1IE = 0; //Reset interrupt flag
while(!IEC0bits.T1IE);// Wait here for timeout
delay--;
}
}
void init_Processor(void)
{
/* uart1 Tx and Rx pin setup */
RPINR18bits.U1RXR = 7; //portB RB7 RX pin
RPOR4bits.RP8R = 3; //portB RB8 TX pin
/* uart2 tx and rx pin setup */
RPINR19bits.U2RXR = 14; //portB RB14 RX pin
RPOR6bits.RP13R = 5; //portB RB13 TX pin
/* uart3 tx and rx pin setup */
RPINR17bits.U3RXR = 10; //portB RB10 RX pin
RPOR5bits.RP11R = 19; //portB RB11 TX pin
//Congifure analog and digital
ANSA = 0x0003;
ANSB = 0x0000;
PORTA = 0x0000;
TRISA = 0X001B;
PORTB = 0x0000;
TRISB = 0x4680;
// Init UART1
U1MODE = 0x8000;
U1STA = 0x3400;
U1BRG = 25;
// Init UART2
U2MODE = 0x8000;
U2STA = 0x3400;
U2BRG = 25;
// Init UART3
U3MODE = 0x8000;
U3STA = 0x3400;
U3BRG = 25;
IFS5bits.U3RXIF = 0;
IEC5bits.U3RXIE = 1;
U3MODEbits.UARTEN = 1;
U3STAbits.UTXEN = 1;
// Init ADC
Timer1DelaymsInit();
GSMPwrkey=1;
}
')
{
uartx1(*s);
s++;
}
}
/* transmit a string in uart3 */
void uartstr3( char *s)
{
while(*s!='%pre%')
{
uartx3(*s);
s++;
}
}
IOCONFIG.h
#include<stdio.h>
#include<stdint.h>
#define GSMPwrkey PORTBbits.RB12
#define GPSreset PORTBbits.RB15
void Timer1DelaymsInit(void);
void Delayms(uint16_t delay);
void init_Processor(void);
void Timer1DelaymsInit(void)
{
T1CONbits.TCKPS = 0; //Timer1 Prescale Select bit
T1CONbits.TCS = 0; //Timer1 Clock source(FOSC/2)
PR1 = 3760;
TMR1 = 0;
IEC0bits.T1IE = 0;
T1CONbits.TON = 1;
}
void Delayms(uint16_t delay)
{
while(delay>0)
{
TMR1 = 0;
IEC0bits.T1IE = 0; //Reset interrupt flag
while(!IEC0bits.T1IE);// Wait here for timeout
delay--;
}
}
void init_Processor(void)
{
/* uart1 Tx and Rx pin setup */
RPINR18bits.U1RXR = 7; //portB RB7 RX pin
RPOR4bits.RP8R = 3; //portB RB8 TX pin
/* uart2 tx and rx pin setup */
RPINR19bits.U2RXR = 14; //portB RB14 RX pin
RPOR6bits.RP13R = 5; //portB RB13 TX pin
/* uart3 tx and rx pin setup */
RPINR17bits.U3RXR = 10; //portB RB10 RX pin
RPOR5bits.RP11R = 19; //portB RB11 TX pin
//Congifure analog and digital
ANSA = 0x0003;
ANSB = 0x0000;
PORTA = 0x0000;
TRISA = 0X001B;
PORTB = 0x0000;
TRISB = 0x4680;
// Init UART1
U1MODE = 0x8000;
U1STA = 0x3400;
U1BRG = 25;
// Init UART2
U2MODE = 0x8000;
U2STA = 0x3400;
U2BRG = 25;
// Init UART3
U3MODE = 0x8000;
U3STA = 0x3400;
U3BRG = 25;
IFS5bits.U3RXIF = 0;
IEC5bits.U3RXIE = 1;
U3MODEbits.UARTEN = 1;
U3STAbits.UTXEN = 1;
// Init ADC
Timer1DelaymsInit();
GSMPwrkey=1;
}