We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I've a problem using the twi-interface from the AT91RM9200 controller. At the moment, I'm not able to transmit any kind of signals (startbyte and so on)... both pins (clock and data) stay always high.
/* crystal frequency */ #define AT91_CRYSTAL 18420000 /* pll param -> processor-frequency */ #define AT91_MASTER_CLK ((AT91_CRYSTAL / 4) * 38 #define MCK (AT91_MASTER_CLK / 3) /* twi clock 100kHz */ #define AT91C_TWI_CLOCK 100000 #define I2C_ADDR 0x48
void AT91F_SetTwiClock(void) { unsigned int sclock; /* Here, CKDIV = 1 and CHDIV=CLDIV ==> CLDIV = CHDIV = 1/4*((Fmclk/FTWI) -6)*/ sclock = (10*MCK /AT91C_TWI_CLOCK); Â' if (sclock % 10 >= 5) sclock = (sclock /10) - 5; else sclock = (sclock /10)- 6; sclock = (sclock + (4 - sclock %4)) >> 2; // div 4 AT91C_BASE_TWI->TWI_CWGR = ( 1<<16 ) | (sclock << 8) | sclock; }
AT91F_TWI_CfgPIO(); AT91F_TWI_CfgPMC(); //disable all interrupts, reset twi, set master mode AT91F_TWI_Configure(AT91C_BASE_TWI); AT91F_SetTwiClock(); //read operation *AT91C_TWI_CR = AT91C_TWI_MSEN | AT91C_TWI_SVDIS; //internal device addr *AT91C_TWI_IADR = 0x01; *AT91C_TWI_MMR = ((I2C_ADDR<<16) //slave addr | AT91C_TWI_MREAD | AT91C_TWI_IADRSZ_1_BYTE); *AT91C_TWI_CR = AT91C_TWI_START | AT91C_TWI_STOP;
I can't find the error causing this problem. Maybe someone of you could give me some useful hints.
best regards Stefan