View previous topic :: View next topic |
Author |
Message |
teccs
Joined: 14 Oct 2006 Posts: 69
|
Posted: Sat Jan 14, 2017 3:43 pm Post subject: Getting 2 microcontrollers to talk to each other |
|
|
I have 2 atmega 1284p's which I am trying to get to communicate together via serial.
Two serial ports on each chip are used. RXD0 and TXD0 are connected to a PC via RS485 USB Converter. That is working fine.
The second serial ports (RXD1 and TXD1) are connected together crossed over between the two pcbs.
I have checked with an oscilloscope on the receive pin on the second pcb and there is serial data there coming from the first pcb.
My code for the two pcbs is below. I have LED's blinking on each board until a character is received. They never stop blinking.
Also, for the first code, when I put in Config serialin = buffered, size = 20 the print #1 statement at the beginning of the code doesn't work. Why isn't buffering working?
$crystal = 18432000 'microcontroller clock frequency
$regfile = "m1284pdef.dat" 'the micro being used
$baud = 19200 ' use baud rate
$baud1 = 19200
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim A As Byte
TxRxControl Alias PORTC.1 'Output - Serial RS485 TX/RX (1/0) control.
LED Alias PORTC.5 'Output
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "com1:" For Binary As #1
Open "com2:" For Binary As #2
WaitMS 500
TxRxControl = 1 'Output - Serial RS485 TX/RX (1/0) control.
Print #1, "Start" ' Print to RS485. This works fine.
Do
Print #2, "2"
LED = 1
WaitMS 500
LED = 0
WaitMS 500
A = Ischarwaiting(2)
Loop Until A = 1
Input #2 , A
Print #1, "A"
Close #1
Close #2
END
SECOND PCB CODE BELOW:
$crystal = 18432000 'microcontroller clock frequency
$regfile = "m1284pdef.dat" 'the micro being used
$baud = 19200 ' use baud rate
$baud1 = 19200
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim A As Byte
LED Alias PORTC.5 'Output
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'Open "com1:" For Binary As #1' Com 1 is actually not used at this point.
Open "com2:" For Binary As #2
Do
LED = 1
WaitMS 500
LED = 0
WaitMS 500
A = Ischarwaiting(2)
Loop Until A = 1
Input #2 , A
Print #2 , A
'Close #1
Close #2
END
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
|
Back to top |
|
|
teccs
Joined: 14 Oct 2006 Posts: 69
|
Posted: Sat Jan 14, 2017 9:27 pm Post subject: Still not working |
|
|
Hi Evert,
Thank you for the reply.
I wish I could say that this fixed it, but it is still behaving the same. Any other ideas? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Jan 14, 2017 9:43 pm Post subject: |
|
|
it would be nice of before you post a bunch of code :
- use the proper indent code (menu , edit, proper indent)
- use the CODE tags on this forum. this make the code look more clear.
Quote: | Also, for the first code, when I put in Config serialin = buffered, size = 20 the print #1 statement at the beginning of the code doesn't work. Why isn't buffering working?
|
you should actually post an example of your code that did not work. I suspect you did not used ENABLE INTERRUPTS, but that is guessing which i do not like.
The help you get is as good as the info you offer.
I also wonder, have you GND connected of the boards? or just tx/rx? _________________ Mark |
|
Back to top |
|
|
teccs
Joined: 14 Oct 2006 Posts: 69
|
Posted: Sat Jan 14, 2017 9:53 pm Post subject: Thank you |
|
|
That worked. Code is now:
Code: |
$crystal = 18432000 'microcontroller clock frequency
$regfile = "m1284pdef.dat" 'the micro being used
$baud = 19200 ' use baud rate
$baud1 = 19200
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim A As Byte
TxRxControl Alias PORTC.1 'Output - Serial RS485 TX/RX (1/0) control.
LED Alias PORTC.5 'Output
Enable Interrupts
Config Serialin = Buffered, Size = 20
Config Serialout = Buffered, Size = 20
Config Serialin1 = Buffered, Size = 20
Config Serialout1 = Buffered, Size = 20
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "com1:" For Binary As #1
Open "com2:" For Binary As #2
WaitMS 500
TxRxControl = 1 'Output - Serial RS485 TX/RX (1/0) control.
Print #1, "Start" ' Print to RS485. This works fine.
Do
Print #2, "2"
LED = 1
WaitMS 500
LED = 0
WaitMS 500
A = Ischarwaiting(#2)
Loop Until A = 1
Input #2 , A
Print #1, "A"
Close #1
Close #2
END
|
This is the code on the second pcb:
Code: |
$crystal = 18432000 'microcontroller clock frequency
$regfile = "m1284pdef.dat" 'the micro being used
$baud = 19200 ' use baud rate
$baud1 = 19200
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
Dim A As Byte
LED Alias PORTC.5 'Output
Enable Interrupts
Config Serialin = Buffered, Size = 20
Config Serialout = Buffered, Size = 20
Config Serialin1 = Buffered, Size = 20
Config Serialout1 = Buffered, Size = 20
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
'Open "com1:" For Binary As #1' Com 1 is actually not used at this point.
Open "com2:" For Binary As #2
Do
LED = 1
WaitMS 500
LED = 0
WaitMS 500
A = Ischarwaiting(#2)
Loop Until A = 1
Input #2 , A
Print #2 , A
Close #1
Close #2
END
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|