I want to use Proteus to simulate UART data transmission, I am going to open two virtual COM ports and connect them.
So I first use Virtual Serial Ports Emulator to open virtual COM ports:
enter image description here
Second, I use tera term to be COM1:
enter image description here
Third, my circuit in Proteus to be COM2:
enter image description here
And I set the COMPIM in the circuit as COM2, baud rate 9600.
enter image description here
The code of dsPIC chip in Proteus:
void main() {
Unlock_IOLOCK();//unlock
PPS_Mapping_NoLock(0, _INPUT, _U1RX);//Set UART1 Rx be pin RP0
PPS_Mapping_NoLock(1, _OUTPUT, _U1TX);//Set UART1 Tx be pin RP1
Lock_IOLOCK();//lock
UART1_Init(9600);//Set Baud Rate
Delay_ms(100);//Let UART initialize
while(1)
{
unsigned receive;
if (UART1_Data_Ready())
{
receive = UART1_Read();
UART1_Write(receive); //The result should be sent back to COM1
}
}
}
Then I started Proteus simulation, then typed a character 'o' in tera term. As you can see, the virtual terminal on Proteus have received 'o', so the virtual COM ports work fine. But dsPIC seems to lose reading the 'o', so it cannot send it to COM1 back.
enter image description here
If I changed the code and restart the simulation
void main() {
Unlock_IOLOCK();//unlock
PPS_Mapping_NoLock(0, _INPUT, _U1RX);//Set UART1 Rx be pin RP0
PPS_Mapping_NoLock(1, _OUTPUT, _U1TX);//Set UART1 Tx be pin RP1
Lock_IOLOCK();//lock
UART1_Init(9600);//Set Baud Rate
Delay_ms(100);//Let UART initialize
while(1)
{
unsigned receive;
UART1_Write('a');
if (UART1_Data_Ready())
{
receive = UART1_Read();
UART1_Write(receive); //The result should be sent back to COM1
}
}
}
I can see 'a' sent by dsPIC in tera term:
enter image description here
So the UART_Write() seems to be OK, I don't know why dsPIC cannot read data from COM1. Maybe I configured something wrong.
-
\$\begingroup\$ I'm not all that familiar with Proteus, but by convention when you go from TTL to RS232 the signals are inverted. If Proteus has a MAX232 or similar maybe try to insert one COMPM and the PIC. It would be needed for a proper circuit anyway, the above would probably fry your UART pins if you made it in real hardware. \$\endgroup\$PeterJ– PeterJ2013年06月14日 14:41:59 +00:00Commented Jun 14, 2013 at 14:41
-
\$\begingroup\$ If TerraTerm works for you, good. I've had better luck with Terminal by Bray. (google "TerminalBpp" to get the site) \$\endgroup\$User.1– User.12013年06月18日 19:32:22 +00:00Commented Jun 18, 2013 at 19:32
-
\$\begingroup\$ Tera Term is free for 32 bit machine, if you use 64 bit machine, you need a license. Thanks for providing another option:-) \$\endgroup\$Po-Jen Lai– Po-Jen Lai2013年06月19日 10:45:45 +00:00Commented Jun 19, 2013 at 10:45
1 Answer 1
I've triedd your code. The problem is that RB0 and RB1 pin is as well AN2 and AN3. Therefore you have to set them to digital. Add this line in the beginning of your code:
ADPCFG = 0xFFFF
and then the Rx pin can receive the data correctly.
BTW. I've tried PeterJ's comment but it seemed not to be the crucial part of this problem. Your original circuit design works fine once you set the analog pin to digital.