0

enter image description hereI am trying to use ARDUINO serial monitor for my PIC microcontroller for debugging purpose, by connecting TX and RX pins of PIC with ARDUINO, I wrote the code for PIC16f877A, which indeed has hardware USART module, using Mikroc compiler, the oscillator frequency is 4MHz, This is working fine when I try to simulate in Proteus, the output is visible both on Serial monitor (Inside Proteus) and also on another microcontroller that I used as receiver for UART but I am unable to get this thing working between PIC and Arduino Uno Physically. The screen (Arduino IDE serial monitor) remains blank. This is the code of PIC transmitter using UART library of Mikroc :

char test[]="Test string Incoming \n";
char *p1;
void main()
{
UART1_init(9600);  //initializing USART module with 9600 baud rate
delay_ms(100);
while(1){
p1=test;
while(*p1){UART1_Write(*p1);   p1++ ;   delay_ms(100);} // writing character one by one on serial transmitter  pin
  }
} 

and This is the code for Arduino Uno which will be acting as a receiver, and then transmit the received character to Serial monitor:

char byt;
void setup() {
  Serial.begin(9600);
  Serial.println("This is uart test!");
}

void loop() {
 if (Serial.available()){
 byt= Serial.read();
 if (byt==' ') Serial.println(); 
 else Serial.print(byt);
 }
}

This is the code for another PIC16F877A that I used as receiver in Proteus simulation.

sbit lcd_rs at rb2_bit;sbit lcd_en at rb3_bit;sbit lcd_d4 at rb4_bit; sbit lcd_d5 at rb5_bit; sbit lcd_d6 at rb6_bit; sbit lcd_d7 at rb7_bit;

sbit lcd_rs_direction at trisb2_bit; sbit lcd_en_direction at trisb3_bit; sbit lcd_d4_direction at trisb4_bit;
sbit lcd_d5_direction at trisb5_bit; sbit lcd_d6_direction at trisb6_bit; sbit lcd_d7_direction at trisb7_bit;
char ch;
void main() 
{
lcd_init();
lcd_cmd(_lcd_clear);
lcd_cmd(_lcd_cursor_off);
lcd_out(1,1,"This is UART test!");
UART1_init(9600);
while(1)
{
if (UART1_Data_Ready)
{ ch=UART1_Read();
 lcd_chr(2,1,ch);}

}

}

Does anyone have any idea regarding this?

  • put Blink sketch into Uno and wire PIC RX to RX and TX to TX. then the USB chip on Uno will be RX to TX to PIC and the USB chip will pass the communication to PIC – Juraj Jul 09 '21 at 09:17

1 Answers1

0

You are using the same Serial port for both sides while you should use Serial for the PC (IDE Serial monitor) and SoftwareSerial or similar library allowing additional serial port on designated pins for the PIC side.

EDIT

enter image description here

Assuming your configuration is correctly described in the above image, you would want to echo what comes from Serial1 (PIC) to Serial (PC) like so:

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if (Serial1.available()) {
    byte inByte = Serial1.read();
    Serial.print(inByte, BYTE);
  }
}
Nino
  • 702
  • 2
  • 6
  • 12
  • I am not getting your point. I have not directly connected the PIC micro to my PC rather I have connected it to Arduino and then Arduino is going to send the message to PC using its FTDI chip. My PC and PIC microcontroller are not directly connected. I think Arduino library already has two different serial modes, when we use Serial.println() it sends the message to PC and the other one is for external TX and RX pin, which has Serial.Read(), Seria.Write() etc. – Mufaddal Darbar Jul 09 '21 at 07:08
  • In that case read from Serial1 (PIC) and write to Serial (PC). – Nino Jul 09 '21 at 07:36
  • I have done same thing in my arduino code mentioned above. Which is first reading from PIC microcontroller and then sending it to PC. – Mufaddal Darbar Jul 09 '21 at 07:51
  • Pay attention to the syntax, Serial vs Serial1 – Nino Jul 09 '21 at 07:54
  • I got your answer but the thing is there is no need to declare two different serial com ports. Can you please explain in detail. – Mufaddal Darbar Jul 09 '21 at 13:50
  • Please check the edited answer, I hope it is clear now, if not please post your exact configuration. – Nino Jul 09 '21 at 14:54
  • I got you, and this time I have declared a separate serial port through Software serial library. but the situation is not resolved, it still doesn't give output , when I connect HC-05 module to Tx and Rx pin (0,1) pin of Arduino and use the same above program to read the value and print the output, it works fine. Also I tried one more thing, when I connect PIC micro to HC-05 module, it works fine, the only thing not working here is that Sending string from PIC to Arduino and Displaying on PC. – Mufaddal Darbar Jul 10 '21 at 06:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/234713/discussion-between-mufaddal-darbar-and-nino). – Mufaddal Darbar Jul 10 '21 at 06:06