Problem pin UART mapping

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
kang_azep
Posts: 1
Joined: 30 Jul 2020 05:25

Problem pin UART mapping

#1 Post by kang_azep » 30 Jul 2020 05:39

Hai guys, I used dsPIC33FJ06GS502. I want to use UART and map pin UART to RP6 and RP7. Here my code

Code: Select all

unsigned char data1 = 0x11, data2 = 0x12;
void main() {
//ADC1_Init();
//uart1_Initial();
Unlock_IOLOCK();
st1=PPS_Mapping(7, _OUTPUT, _U1TX);//setting pin TX_UART1
st2=PPS_Mapping(6, _INPUT,_U1RX);//setting pin RX_UART1
Lock_IOLOCK();
Delay_ms(100);
UART1_Init(9600);
Delay_ms(100);
//u= trapz1(20,100,200);
 while (1){
   Delay_ms(500);
   UART_Write(data1);
   }
}
When I test pin RP6&RP7, the data can not be shown. What wrong is that code?
Thanks

User avatar
stefan.filipovic
mikroElektronika team
Posts: 1135
Joined: 18 Dec 2018 10:30

Re: Problem pin UART mapping

#2 Post by stefan.filipovic » 30 Jul 2020 15:55

Hi,

Could you try this way?

Code: Select all

void main() {

  ADPCFG = 0x3F;      // Configure AN pins as digital I/O
  TRISA = 0;             // Set direction to be output
  TRISB = 0;             // Set direction to be output

  LATA = 0;
  LATB = 0;              // Turn OFF the PORTB LEDs
  Unlock_IOLOCK();
  PPS_Mapping_NoLock(7, _OUTPUT, _U1TX);
  PPS_Mapping_NoLock(6, _INPUT, _U1RX);
  Lock_IOLOCK();
  
  UART1_Init(9600);
  Delay_ms(100);
  UART_Write_Text("START\n\r");
  
  while (1) {
     if(UART1_Data_Ready()) {
        UART1_Write(UART1_Read());
     }
  }
}
Make sure to set the configuration words properly in the Edit Project window.

Kind regards,
Stefan Filipović

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”