Hello!
To understand the problem, I will tell you about my project. There are two devices - one device has a 3x7 segment display that indicates the temperature of the DS18B20 or running messages. The display mode depends on the temp value of the Hserreceive from the other device. The other device will consist of a fan control with HPWM, a photo sensor of the analog input, a timer, led by HPWM ... depending on the mode of operation, the second device sends a display byte through Hsersend, which will set the display mode. I created a test code for both devices. The main problem is that the byte tempvalue that is sent from the second device to the display through the serial port is unstable. The test code is intended to test how HserSend works. The test sends 3 values (0, 1, 2) each at a time. Everything works at least normal, unless the program code contains the HPWM instruction ... Inserting the program code into HPWM, Hsersend begins to byte broadcast intermittently. Due to this, the display starts to distort the running message. I have no communication experience. I can not continue to build the program code :( Help ludz. I hope you understand my story.
I add both program codes.
second device program code (tx)
#chip 16F886, 4
#config osc=int
;Setup LCD Parameters
#define LCD_IO 4
#define LCD_NO_RW
'' #define LCD_Speed fast
; ----- Define Hardware settings
#define LCD_RS PORTc.4
#define LCD_Enable PORTc.5
#define LCD_DB4 PORTb.3
#define LCD_DB5 PORTb.2
#define LCD_DB6 PORTb.1
#define LCD_DB7 PORTb.0
dir portc.2 out
tempvalue=0
#define USART_BAUD_RATE 9600
Dir PORTc.6 out ' Tx 'Set USART transmit pin to output
dim aa as word
cycle:
'' test programmm
aa++
if aa=>4000 then aa=0
if aa<1000 then tempvalue=1
if aa>1000 & aa<2000then tempvalue=0
if aa>2000 then tempvalue=2
HSerSend tempvalue
locate 0, 0
Print "Hello World."
HPWM 1, 40, 26
wait 10 ms
goto cycle
Also, the lcd display function interferes with serial port operation. for example cls and other lcd instructions. but my project will also have a display provided.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You have chosen to experience one of the most popular problems. Communicating between two PICs.
use "Divide and Conquer" troubleshooting. You have a display on both ends of the comm line. use extra print/display statements on both PICs to see what is happening. Also slow things down( longer wait) so they become more apparent where the problem lies.
On the Tx Pic, i don't think the HPWM statement should interfere.
I would use your LCD to print both the "aa" value and the the "tempvalue" variables to the LCD.
On the Rx PIC i do see a conflict. When reading temperature you are using the 3x7seg display to display using the interrupt "showdigit" to jump between digits at intervals of timer0. For the messages you are not using the interrupt but driving them directly with DisplayChar which is overriding the other display. We need to make the "showdigit" into a "showchar" intterrupt sub so they are not in conflict.
OR shut the interrupt off when not using it. I like the first option of making it work with both char and numbers.
Another problem is "HSerReceive tempvalue". HSerReceive sends back a default value(255) if there is no data available. You need to check for new data if you want to receive only you data(0,1,2).
'If there is no new data, HSerReceive will return default value. comport = 1 HSerReceive Rxvalue If Rxvalue <> 255 Then ‘ don’t change your value if it is default tempvalue = Rxvalue End If
Even better way is:
IfUSARTHasDatathenHSerReceivetempvalueEndIf
I hope this helps. i will look at rewriting the "showdigit" intterrupt routine to do both as time allows.
GL
Mike
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
To understand the problem, I will tell you about my project. There are two devices - one device has a 3x7 segment display that indicates the temperature of the DS18B20 or running messages. The display mode depends on the temp value of the Hserreceive from the other device. The other device will consist of a fan control with HPWM, a photo sensor of the analog input, a timer, led by HPWM ... depending on the mode of operation, the second device sends a display byte through Hsersend, which will set the display mode. I created a test code for both devices. The main problem is that the byte tempvalue that is sent from the second device to the display through the serial port is unstable. The test code is intended to test how HserSend works. The test sends 3 values (0, 1, 2) each at a time. Everything works at least normal, unless the program code contains the HPWM instruction ... Inserting the program code into HPWM, Hsersend begins to byte broadcast intermittently. Due to this, the display starts to distort the running message. I have no communication experience. I can not continue to build the program code :( Help ludz. I hope you understand my story.
I add both program codes.
second device program code (tx)
Display DEVICE CODE (Rx)
Also, the lcd display function interferes with serial port operation. for example cls and other lcd instructions. but my project will also have a display provided.
JANIS,
You have chosen to experience one of the most popular problems. Communicating between two PICs.
use "Divide and Conquer" troubleshooting. You have a display on both ends of the comm line. use extra print/display statements on both PICs to see what is happening. Also slow things down( longer wait) so they become more apparent where the problem lies.
On the Tx Pic, i don't think the HPWM statement should interfere.
I would use your LCD to print both the "aa" value and the the "tempvalue" variables to the LCD.
On the Rx PIC i do see a conflict. When reading temperature you are using the 3x7seg display to display using the interrupt "showdigit" to jump between digits at intervals of timer0. For the messages you are not using the interrupt but driving them directly with DisplayChar which is overriding the other display. We need to make the "showdigit" into a "showchar" intterrupt sub so they are not in conflict.
OR shut the interrupt off when not using it. I like the first option of making it work with both char and numbers.
Another problem is "HSerReceive tempvalue". HSerReceive sends back a default value(255) if there is no data available. You need to check for new data if you want to receive only you data(0,1,2).
Even better way is:
I hope this helps. i will look at rewriting the "showdigit" intterrupt routine to do both as time allows.
GL
Mike
Why not try I2C between the two? Works ok.
Thanks, mmotte! I will try!
Anobium, as I said, I have no experience with communications. this is the first project. The devices will be connected by cable of approx. 1.5m ....
I tried
If USARTHasData then HSerReceive tempvalue End if
Its work!
I2C is a short distance. How much is the maximum distance?
I have a question, where is the description in Help about the USARTHasData command?