how to read eeprom mac id from my custom board. controller is mk10dx256. eeprom is microchip /24AA025E64.adress i have to access is 0xfa. i have to read last 6 bits to get the unique mac id of the eeprom.
data sheet of eeprom
http://ww1.microchip.com/downloads/en/devicedoc/20002124g.pdf
program:
#include <__cross_studio_io.h>
#include "MK10DZ10.h"
#define MWSR 0x00 /* Master write */
#define MRSW 0x01 /* Master read */
#define reg EEPROM
void i2c_Wait(void);
i2c_Wait()
{
while((I2C1_S & I2C_S_IICIF_MASK)==0) {
}
// Clear the interrupt flag
I2C1_S |= I2C_S_IICIF_MASK;
}
main()
{
unsigned char u8Address;
unsigned char u8Register;
unsigned char u8Data = 'a';
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;
PORTC_PCR10 |= PORT_PCR_MUX(2);
PORTC_PCR11 |= PORT_PCR_MUX(2);
//i2c1
SIM_SCGC4 |= (SIM_SCGC4_I2C1_MASK);
// START I2C
I2C1_C1 |= ( I2C_C1_TX_MASK );
I2C1_C1 |= ( I2C_C1_MST_MASK ) ;
I2C1_C1 |= ( I2C_C1_IICEN_MASK ) ;
I2C1_C1 |= ( I2C_C1_TXAK_MASK ) ;
I2C1_C1 |= ( I2C_C1_IICIE_MASK ) ;
I2C1_C1 |= ( I2C_C1_RSTA_MASK ) ;
I2C1_D = u8Data;
I2C1_F = 0;
I2C1_F = 0x80;
I2C1_F |= I2C_F_ICR( 0x18 ) ;
//i2c_Wait()
//{
// while((I2C1_S & I2C_S_IICIF_MASK)==0) {
// }
// // Clear the interrupt flag
// I2C1_S |= I2C_S_IICIF_MASK;
//}
//STOP I2C
//I2C1_C1 &= ~( I2C_C1_TX_MASK );
unsigned char I2C_ReadRegister_uc (unsigned char u8Address, unsigned char u8Register ){
unsigned char u8Data;
unsigned char u8AddressW, u8AddressR;
/* shift ID in right position */
u8AddressW = (u8Address << 1) | MWSR; // Write Address
u8AddressR = (u8Address << 1) | MRSW; // Read Address
/* send start signal */
//i2c_Start();
I2C1_C1 |= ( I2C_C1_TX_MASK );
I2C1_C1 |= ( I2C_C1_MST_MASK ) ;
/* send ID with Write bit */
//i2c_write_byte(u8AddressW);
I2C1_D = u8AddressW;
i2c_Wait();
// send Register address
//i2c_write_byte(u8Register);
I2C1_D = u8Register;
printf("register");
i2c_Wait();
// send repeated start to switch to read mode
//i2c_RepeatedStart();
I2C1_C1 |= ( I2C_C1_RSTA_MASK ) ;
// re send device address with read bit
//i2c_write_byte(u8AddressR);
I2C1_D = u8AddressR;
i2c_Wait();
// set K40 in read mode
// i2c_EnterRxMode();
I2C1_C1 &= ~I2C_C1_TX_MASK;
I2C1_C1 |= I2C_C1_TXAK_MASK;
u8Data = I2C1_D;
//i2c_read_byte();
// send stop signal so we only read 8 bits
//i2c_Stop
I2C1_C1 &= ~( I2C_C1_TX_MASK );
debug_printf("%c",u8Data);
return 1;
}
while(1)
{I2C_ReadRegister_uc(0xFA,' $$');}
}
$$ i cant fnd the register name to access.
while i tried to run it was printing FA directly.