by KurtE » Mon Sep 04, 2006 3:07 am
by KurtE
Mon Sep 04, 2006 3:07 am
limor wrote:please excuse a software guy's humble ignorance.
I dont understand the serial communication wireing. To send a bit to the coms line, the MCU has to put PD0 on 0 and/or PD6 on 1? and similarly when the imcoming signal is high (or low) what happens to PD7 and PD1?
(Correction: sending data involves PD0 and PD6 / receiving involves PD7 and PD1.. but my question remains) ![Embarassed :oops:](images/smilies/icon_redface.gif)
I believe that he is using two I/O pins PD6 and PD7 combined to form the direction port as shown in the CM-5 internal circuit (HALF DUPLEX UART). Their diagram uses an 74HC04 inverter to make sure that only TXD or RXD is active, but not both. In Mark's circuit the controlling software would have to make sure that only one of these two pins is set high at any point.
I assume that you will want to use the builtin USART support that is in the ATMEGA8 chip. So your code may look something like: (Note this code is sortof based off of the C++ classes that are defined in the Seattle Robotics Society Workshop robot level 2 examples. These are up at:
http://www.seattlerobotics.org/WorkshopRobot/level2/index.php
- Code: Select all
OUT RXEnable ('D', 6);
OUT TXEnable ('D', 7, false);
COMM comm ('D', 0,
'D', 1);
...
// To output a packet you might try something like
RXEnable.Low();
TXEnable.High();
// For each byte in the packet you might call something like:
comm.TxCh(ch); // waits for bit_is_clear(UCSRA, UDRE)
// before setting UDR= ch
...
// To receive information you might do something like:
TxEnable.Low():
RxEnable.High();
// Set up a loop to read in a packet with all of the appropriate
// error checking...
while(!comm.IsCharWaiting()) ; // checks RXC bit in UCSRA
ch = comm.InKey(); // gets byte from UDR register
Note in the example code above you could replace the polling for input character available or transmit complete with interrupts...
Please forgive me if I misunderstood the schematic as I am also a software guy!
limor wrote:please excuse a software guy's humble ignorance.
I dont understand the serial communication wireing. To send a bit to the coms line, the MCU has to put PD0 on 0 and/or PD6 on 1? and similarly when the imcoming signal is high (or low) what happens to PD7 and PD1?
(Correction: sending data involves PD0 and PD6 / receiving involves PD7 and PD1.. but my question remains) ![Embarassed :oops:](images/smilies/icon_redface.gif)
I believe that he is using two I/O pins PD6 and PD7 combined to form the direction port as shown in the CM-5 internal circuit (HALF DUPLEX UART). Their diagram uses an 74HC04 inverter to make sure that only TXD or RXD is active, but not both. In Mark's circuit the controlling software would have to make sure that only one of these two pins is set high at any point.
I assume that you will want to use the builtin USART support that is in the ATMEGA8 chip. So your code may look something like: (Note this code is sortof based off of the C++ classes that are defined in the Seattle Robotics Society Workshop robot level 2 examples. These are up at:
http://www.seattlerobotics.org/WorkshopRobot/level2/index.php
- Code: Select all
OUT RXEnable ('D', 6);
OUT TXEnable ('D', 7, false);
COMM comm ('D', 0,
'D', 1);
...
// To output a packet you might try something like
RXEnable.Low();
TXEnable.High();
// For each byte in the packet you might call something like:
comm.TxCh(ch); // waits for bit_is_clear(UCSRA, UDRE)
// before setting UDR= ch
...
// To receive information you might do something like:
TxEnable.Low():
RxEnable.High();
// Set up a loop to read in a packet with all of the appropriate
// error checking...
while(!comm.IsCharWaiting()) ; // checks RXC bit in UCSRA
ch = comm.InKey(); // gets byte from UDR register
Note in the example code above you could replace the polling for input character available or transmit complete with interrupts...
Please forgive me if I misunderstood the schematic as I am also a software guy!