My very simple ASF program for Mega32 is configuring the wrong registers when using ioport_set_pin /set_dir
#define I2C_SDA IOPORT_CREATE_PIN(PORTC, 1) #define I2C_CLK IOPORT_CREATE_PIN(PORTC, 0) a= I2C_CLK; // to check value b= IOPORT_DIR_OUTPUT; // to check value
ioport_set_pin_dir(I2C_CLK, IOPORT_DIR_OUTPUT); ioport_set_pin_dir(I2C_SDA, IOPORT_DIR_OUTPUT);
Instead of PORTC, direction register at 0x34, it's hitting the ADMUX at Register address 0x27
i.e. the disassembled code shows the instruction sbi 0x07,0 which I assume gets the register offset added automatically.
I think it should be sbi 0x14,0
I've added local variables a and b to see the definitions before it gets to do anything. I2C_CLK is fixed at 0x10.
I'm a bit stumped because it was a Studio generated ASF program ( on a user defined board ).
I've attached the whole project in case anyone feels inclined .. it's got I2C drivers for TSL2561 in it.. but of course I can't get that far because the port pins dont even get set up correctly.
a= I2C_CLK; 0000018C LDI R24,0x10 Load immediate 0000018D STS 0x006D,R24 Store direct to data space b= IOPORT_DIR_OUTPUT; 0000018F LDI R24,0x01 Load immediate 00000190 STS 0x006C,R24 Store direct to data space --- C:\Users\Rob\Dropbox\AVR\Studio 7\../../src/ASF/common/services/ioport/mega/ioport.h base->DIR |= arch_ioport_pin_to_mask(pin); 00000192 SBI 0x07,0 Set bit in I/O register 00000193 SBI 0x07,1 Set bit in I/O register = (base_add->PORTDATA | arch_ioport_pin_to_mask 00000194 SBI 0x08,0 Set bit in I/O register 00000195 SBI 0x08,1 Set bit in I/O register