Hi , I am trying to use I2C in a 908JL16, but is not working, I am following the tutor from freescale.
I use the following code
void init_I2C (void)
{
MMCR_MMEN = 1; // Enable IIC;
MIMCR_MMBB = 1; // Clear bus busy flag;
MMCR_MMTXAK = 1;
MIMCR_MMRW = 0; // R/W bit = 0;
MIMCR_MMAST = 0; // Slave mode actually;
MIMCR_MMNAKIF = 0;
MIMCR_MMALIF = 0; // Clear flags;
MMSR = 0; // Clear all flags (Status register);
MIMCR_MMBR = 4; // Set speed to 78kHz for Bus = 2.46 MHz;
}
/* Funcion para enviar por I2C a un esclavo*/
void I2C_write_byte (byte addr, byte wr_data)
{
MIMCR_MMRW = 0; // Set Write mode;
MMADR = 100; // set combined address of Slave for write;
MMDTR = addr; // set address of Slave to read;
//-------start of transmit bytes to IIC bus-----
MIMCR_MMAST = 1; // Start transfer - Master bit = 1;
while (!(MMSR_MMTXBE)); // wait till data transferred;
while (MMSR_MMRXAK); // wait for ACK from slave;
//-----Slave ACK occurred------------
MMDTR = wr_data; // write data byte into EEPROM;
while (!(MMSR_MMTXBE)); // wait till data transferred;
MMDTR = 0xFF; // generate SCL impulse for slave to send ACK bit;
while (MMSR_MMRXAK); // wait for ACK from slave;
MIMCR_MMAST = 0; // STOP bit;
}
/* Funcion para leer por I2C a un esclavo*/
byte I2C_read_byte (byte addr)//output is byte "rd_data";
{
byte rd_data;
MIMCR_MMRW = 0; // Set Write mode;
MMADR = 100; // set combined address of Slave for write;
MMDTR = addr; // set address;
//-------start of transmit first byte to IIC bus-----
MIMCR_MMAST = 1; // Start transfer - Master bit = 1;
while (!(MMSR_MMTXBE)); // wait till data transferred;
while (MMSR_MMRXAK); // wait for ACK from slave;
//-----Slave ACK occurred------------
MIMCR_MMRW = 1; // set read operation;
MMCR_REPSEN = 1; // enable repeat Start bit;
MMCR_MMTXAK = 0; // Master will generate ACK;
MIMCR_MMAST = 1; // Start transfer - Master bit = 1;
//------start of transmit Repeat start & "A1" to IIC bus-------
MMDTR = 0xFF; // send repeated start and combined address;
while (!(MMSR_MMTXBE)); // wait till data transferred;
while (MMSR_MMRXAK); // wait for ACK from slave;
MMDTR = 0xFF; // send SCL clocks for the slave to send data;
MMCR_MMTXAK = 1; // Disable master ACK after read byte from Slave;
while (!(MMSR_MMRXBF)); // wait till data received;
rd_data = MMDRR; // read received data;
MIMCR_MMAST = 0; // generate STOP bit - End of transfer;
return rd_data;
}
/* Funcion para enviar string por I2C*/
void I2C_write_str(byte addr, byte *str)
{
byte i=0;
while (str[i]!='~'){
I2C_write_byte(addr,str[i]);
i++;
}
}
Thanks
Sorry to interfere, but my hope (working on a program for this mcu and module, but not having touched the hardware) is that they do! I presume you mean "as opposed to PTD(7&6)" - so having made the pin selection and enabled the module I would say "yes". Check out the 3rd parapraph in section 8.1 in conjunction with the note at the bottom of section 8.1, p.109 of rev 1.1 datasheet.
Now: how about your opinion on my post a few days ago about this mcu and module - thanks! :smileyhappy:
Jim