Hi everyone, I'm hoping you can help me with this little problem...
I've patched optiboot.c to control the DE line for an RS-485 driver when sending data, in hopes that I could get to programming my device over RS-485 (it's a custom board, and I'd prefer to not have to fiddle around and switch all sorts of stuff to program vs. interact with it - the RS-485 driver's output are properly hooked up to standard TX/RX, and communication works fine over RS-485, and TTL serial works fine when I disable the driver via a hardware jumper).
In a quest to perform this activity, I've added the following to optiboot.c's putch() function:
void putch(char ch) {
#ifndef SOFT_UART
PORTD |= _BV(PORTD5);
PORTB |= _BV(PORTB5);
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
PORTD &= ~_BV(PORTD5);
PORTB &= ~_BV(PORTB5);
Digital 5 is the DE pin, and digital 13 is just there for debug purposes. I've also included the requisite DDR.. instructions up in main():
DDRD |= _BV(PORTD5);
DDRB |= _BV(PORTB5);
... and clocked it back to 9600 for uploading*, as speed isn't as important as simply being able to use the RS-485 interface, added a boards definition, and so forth.
-
- this required adding a define to get around the SOFT_UART automatic definition, which triggered all sorts of errors compiling.
All this is fine and dandy, got it up to the board, etc. and then got the inevitable timeouts during sketch upload (replicating process that would've happened using the TTL interface successfully when defined as a duemilanove w/ atmega328p.).
As a consequence, I didn't see my pin13 light up during the process - and I know I've had issues with time to clear out bits from the RS-485 driver when switching the DE pin state, so I thought I'd add a delay, which is where I hit the real roadblock:
#include <util/delay.h>
...
void putch(char ch) {
#ifndef SOFT_UART
PORTD |= _BV(PORTD5);
PORTB |= _BV(PORTB5);
_delay_ms(1);
This triggers an error during hex upload:
avrdude: input file optiboot_nanoMoCo.hex auto detected as Intel Hex
avrdude: ERROR: address 0x8008 out of range at line 33 of optiboot_nanoMoCo.hex
avrdude: write to file 'optiboot_nanoMoCo.hex' failed
Any thoughts on the best way to add a delay here for testing purposes? Or, perhaps, any recommendations towards the overall goal? (Programming over RS-485 interface.)
Thanks!
!c