Hi guys,
I am experiencing some issues when trying to make two PIC18F1320 to communicate each other by using the Hardware UART port.
Basically, I connected together the TX/RX ports of a PIC to the RX/TX ports of the other one, and then I wrote two very trivial pieces of code, one continuously sending some bytes and the other one continuously receiving them.
Here are the two pieces of code:
#chip 18F1320, 8
#define USART_BAUD_RATE 9600
#define USART_BLOCKING true
#define SerInPort PORTb.4
#define SerOutPort PORTb.1
Dir SerOutPort Out
Dir SerInPort In
main:
wait 500 ms
HSerPrint "Z"
GoTo Main
The other one, instead, is:
'same defines as before
...
Dir SerOutPort Out
Dir SerInPort In
Dim buffer as Byte
main:
wait 500 ms
byte = HSerReceive
' Blink a LED
...
GoTo Main
Unfortunately, the LED doesn't blink, even if I see some movement on the serial line...
Am I missing something? Am I using the HSerPrint/HSerReceive methods in a wrong way?
Thank you,
Matteo
edit:
to avoid issues, I have tried to explicitly disable any other thing that might occur on the same pins, by disabling the A/D converters and all the interrupts, but unfortunately nothing changed :(
Last edit: ma1069 2014-06-15
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Usual question,the better the POLLING or the use of the interrupt.
Depends on the code.
If all interrupts are in use.
If you use the Timmer(discouraged any type of polling).
To evaluate the interference on the line and the dispersion voltage.
So the greater the distance,the greater are the disorders.
It would be appropriate(after,in the second time)to evaluate the possibility of using RF modules for short and medium distances..
The same applies to the I2C discorsso regarding the distances.
Even if you can "stretch" creating "amplifiers" signal BUS.
However,the I2C is much easier to manage and implement(highly recommended for short distances)
Try this code and let us know
MASTER
#CHIP 18F1320,8
#DEFINE USART_BAUD_RATE 9600
#DEFINE USART_BLOCKING TRUE
DIR PORTB.1 OUT
'DIR PORTB.4 IN 'Not set,so do not use it to get date.for now....
Hi guys,
I am experiencing some issues when trying to make two PIC18F1320 to communicate each other by using the Hardware UART port.
Basically, I connected together the TX/RX ports of a PIC to the RX/TX ports of the other one, and then I wrote two very trivial pieces of code, one continuously sending some bytes and the other one continuously receiving them.
Here are the two pieces of code:
The other one, instead, is:
Unfortunately, the LED doesn't blink, even if I see some movement on the serial line...
Am I missing something? Am I using the HSerPrint/HSerReceive methods in a wrong way?
Thank you,
Matteo
edit:
to avoid issues, I have tried to explicitly disable any other thing that might occur on the same pins, by disabling the A/D converters and all the interrupts, but unfortunately nothing changed :(
Last edit: ma1069 2014-06-15
Please have a look at http://gcbasic.sourceforge.net/help/serialrs232bufferring.htm this may help.
That was my starting point: the code I wrote took inspiration from that, but unfortunately it doesn't work... What do you think I could be missing?
Oh.
Does the interrupt work on the chipset you are using? That is the first place I would start.
But, communications maybe be easier using I2C. What is the distance or requirements for Serial comms?
Usual question,the better the POLLING or the use of the interrupt.
Depends on the code.
If all interrupts are in use.
If you use the Timmer(discouraged any type of polling).
To evaluate the interference on the line and the dispersion voltage.
So the greater the distance,the greater are the disorders.
It would be appropriate(after,in the second time)to evaluate the possibility of using RF modules for short and medium distances..
The same applies to the I2C discorsso regarding the distances.
Even if you can "stretch" creating "amplifiers" signal BUS.
However,the I2C is much easier to manage and implement(highly recommended for short distances)
Try this code and let us know
MASTER
#CHIP 18F1320,8
#DEFINE USART_BAUD_RATE 9600
#DEFINE USART_BLOCKING TRUE
DIR PORTB.1 OUT
'DIR PORTB.4 IN 'Not set,so do not use it to get date.for now....
Ciclo:
DO
HSerSend 90 '90 is the ASCII value of Z
WAIT 200 ms 'More than ample time to execute code from the slave
LOOP
SLAVE
#CHIP 18F1320,8
#DEFINE USART_BAUD_RATE 9600
#DEFINE USART_BLOCKING TRUE
'DIR PORTB.1 OUT 'Not set,so do not use it to trasmit date.for now....
DIR PORTB.4 IN
Ciclo:
DO
HSerReceive InputByte
IF InputByte=90 THEN '90 is the ASCII value of Z
IF PORTA.0=0 THEN 'If the LED is off..
SET PORTA.0 ON 'I turn on the LED,the port chosen at random
ELSE 'If the LED is on..
SET PORTA.0 OFF 'I turn off the LED,the port chosen at random
END IF
END IF
LOOP
Last edit: alejandro1957 2014-06-19