Software > Software

AVR port config

(1/2) > >>

Admin:
How do I set individual ports on the AVR to be output pins without doing a bit mask?

for example, this is my current code:

--- Code: ---//configure ports for input or output - specific to ATmega8
void configure_ports(void)
{
DDRC = 0x00;  //configure all C ports for input
PORTC = 0x00; //make sure pull-up resistors are turned off
DDRD = 0xFF;  //configure all D ports for output
//PORTB0 =1;//???
//PORTB6 =1;//???
//PORTB7 =1;//???
}

--- End code ---

and the pinout
http://www.societyofrobots.com/images/sbs_avr_schematic.png

The reason I dont want to do a DDRB = whatever mask is because I am afraid of messing up the MISO/MOSI stuff that is also on PORT B (a mistake could prevent me from doing future programming on my AVR)

rgcustodio:
Bit masking is the way to go. The register is setup like that by Atmel so we have no choice.

I think you don't have to worry about messing up MISO and MOSI (ie setting them up both as inputs or as outputs). Before the ISP programmer (and software) starts programming, the MCU is reset (RESET line goes low). So any settings you make in your program should not affect SPI programming.

What you should be wary of is setting the RESET line as an I/O pin in the fuse bit settings. This will render your MCU un-programmable by SPI. High-voltage programming will be your last option.

Admin:
whoa!

ok so I can use those ports both for the programmer and servos without interference issues?

rgcustodio:
Ooops sorry to get your hopes up, I need to rephrase my statements.

You can set them up one at a time only. You can program them as I/O in your application. Then when you want to reprogram the MCU via ISP, the protocol resets the robot and uses MISO and MOSI as specified in ISP programming. You can not however, program these pins as I/O then use them as MISO and MOSI at the same time.


--- Quote ---ok so I can use those ports both for the programmer and servos without interference issues?
--- End quote ---
Actually, behind the scenes, the MCU is reset before programming. When the MCU is reset your application is not running so the ISP programmer/software can use the MOSI and MISO pins as expected.

Admin:

--- Quote ---You can not however, program these pins as I/O then use them as MISO and MOSI at the same time.

--- End quote ---
yea I understood that part

So it just occured to me that if I output stuff to the MISO/MOSI lines, wouldnt that damage the programmer?

Navigation

[0] Message Index

[#] Next page

Go to full version