View previous topic :: View next topic |
Author |
Message |
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Tue May 30, 2017 4:59 pm Post subject: UART Communication between two ATMEGA164P |
|
|
Hello Everyone
Attached is my Hardware Schematic.
I am trying to send data from MICRO2 to MICRO1
I have FT232 for USB communication on both MICRO's UART1
I have connected the RX0 of MICRO2 to TX0 of MICRO1 & TX0 of MICRO2 to RX0 of MICRO1
MICRO 2 code
Code: | $regfile = "M164pdef.dat"
$crystal = 14745600
$hwstack = 80
$swstack = 80
$framesize = 80
$baud = 57600
Config Serialin = Buffered , Size = 8
Do
Print 2
Waitms 50
Loop |
MICRO 1 Code
Code: | $regfile = "M164pdef.dat"
$crystal = 14745600
$hwstack = 80
$swstack = 80
$framesize = 80
$baud = 57600
Config Com1 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 8
Open "COM1:" For Binary As #1
Open "COM2:" For Binary As #2
Dim A As Byte
Do
A = Ischarwaiting()
Print #2 , A
Loop
|
The output is always 0.
I also tried the INPUT command but nothing worked.
Thank you for the help
(BASCOM-AVR version : 2.0.7.5 , Latest : 2.0.7.8 ) |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Tue May 30, 2017 6:12 pm Post subject: |
|
|
For buffered Serialin you must Enable Interrupts in MICRO 1 Code |
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Tue May 30, 2017 7:20 pm Post subject: |
|
|
Thank you sooo much. I am glad I asked. I would had tried everything else in the world. |
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Tue May 30, 2017 7:24 pm Post subject: |
|
|
One more question
How can I read a Single Data type over UART.
e.g.
Speed = 11.85
Print Speed
How should I read it on other MICRO
I tried INPUT command |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Wed May 31, 2017 6:41 am Post subject: |
|
|
Code: | Dim S As Single
Dim B As Byte
''''''''''''''''''''''''''''
Do
B = Ischarwaiting(#1)
If B = 1 Then
Input #1 , S
Print #2 , "number = " ; S
End If
Loop |
|
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Wed May 31, 2017 3:21 pm Post subject: |
|
|
Thank you for the reply.
I tried the exact same code. The output is always 0.0
number = 0.0
Any other recommendation |
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Wed May 31, 2017 3:46 pm Post subject: |
|
|
here is the code for MICRO2
Code: | $regfile = "M164pdef.dat"
$crystal = 14745600
$hwstack = 80
$swstack = 80
$framesize = 80
$baud = 57600
Config Serialin = Buffered , Size = 8
Config Serialout = Buffered , Size = 8
Enable Interrupts
Dim Speed_avg As Single
Speed_avg = 5.0
Do
Print Speed_avg
Waitms 10
Loop |
Here is the receiver code MICRO 1
Code: | $regfile = "M164pdef.dat"
$crystal = 14745600
$hwstack = 80
$swstack = 80
$framesize = 80
$baud = 57600
Config Com1 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = 57600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Serialin = Buffered , Size = 20
Config Serialin1 = Buffered , Size = 20
Open "COM1:" For Binary As #1
Open "COM2:" For Binary As #2
Dim Speed As Single
Dim A As Byte
Enable Interrupts
Do
A = Ischarwaiting(#1)
If A = 1 Then
Input #1 , Speed
Print #2 , "number = " ; Speed
End If
Loop |
OUTPUT is number = 0.0 |
|
Back to top |
|
|
Visovian
Joined: 31 Oct 2007 Posts: 584 Location: Czech
|
Posted: Thu Jun 01, 2017 7:41 am Post subject: |
|
|
Then search for the fault in hardware. |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Thu Jun 01, 2017 11:17 am Post subject: |
|
|
Hw can't work this way.
U6 R2OUT is connected to Micro1 TXD and Micro2 RXD.
When Micro1 tries to send something over the TXD line U6 is still pulling on it with the result that that voltage level on the line will not change.
So Micro1 can't send because of this. You can verify it with a scope or simple remove U6 to see if it works. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
allsetgo
Joined: 15 Jun 2016 Posts: 21
|
Posted: Mon Jun 05, 2017 2:58 pm Post subject: |
|
|
Thank you for the suggestions.
The HW works fine even with MAX232 IC mounted. I also removed it and tried
The INPUT command works fine with string data type.
Inputbin and InputHex commands work fine.
Single char transfer works fine too
It's sending and receiving Single/Integer data type is not working with INPUT command |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
|