2010年9月1日 星期三

Atmega 128 Port C as normal I/O

I am trying to use PC0-PC7 as normal I/O on an Atmega 128. The lower external address bits AD0-AD7 are used for external memory and function correctly. PC0-PC7 are released for normal I/O in XMCRB. All reads of Port C and PORTC in Studio's I/O window are 1's (pullups enabled) and 0's (pullups disabled). What am I missing?

MCUCR = 0x80; // enable external memory, no wait states, disable
// sleep, sleep mode idle, int vectors not in boot
// flash, no int vector change enable
XMCRA = 0x00; // no external memory sectors, no wait states
XMCRB = 0x07; // release high address bits for normal i/o
DDRC = 0x00; // set pc7-pc0 inputs
PORTC = 0xff; // enable pc7-pc0 pullups
//PORTC = 0x00; // disable pc7-pc0 pullups
while(1)
{
key = PORTC;
}
solution :

1. Turn off ATMega103 fuse. In atmega103 mode PORTC is output only!

2. The read should be from PINC and not PORTC.

3. When the XMEM interface is enabled, the XMEM interface will override the setting in the
data direction registers that corresponds to the ports dedicated to the XMEM interface.
For details about the port override, see the alternate functions in section  I/O Ports on
page 63.
     It says nothing about exempting the bits you choose not to use for addresses. In fact, the tables on page 74/75 explicitly show the port override depends only on the XMM bit. So it looks like you're stuck with Port C as output as long as you have external memory enabled.

4. On page 31 it talks about releasing port pins for normal I/O by setting the XMM bits when external memory is used. If what you are saying is correct, then wouldn't the XMM bits would be useless?

     Just tried clearing SRE in MCRCR (no external memory) and the results are the same - port C inputs do not change. It looks like the external memory issue is a "red herring" and the problem is that port C is not working at all.

MCUCR = 0x00; // disable external memory, no wait states, disable sleep,
XMCRA = 0x00; // no external memory sectors, no wait states
PORTB = 0x81; // enable pb7,pb0 pullups
DDRC = 0x00; // set pc7-pc0 inputs
PORTC = 0xff; // enable pc7-pc0 pullups
data = PINC;

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。