本帖最后由 chujunzbdx 于 2016-3-23 21:34 编辑
创龙TMS320C665x开发板含有一个1Mbit 大小 I2C 接口 的 EEPROM。
IIC协议开始停止状态
IIC接口协议
发送的7位slave地址流程 1.关于EEPROM的结构体定义
- typedef struct {
- int32_t manufacturer_id; /**
- int32_t device_id; /**
- PLATFORM_DEVICE_TYPE type; /**
- int32_t width; /**
- int32_t block_count; /**
- int32_t page_count; /**
- int32_t page_size; /**
- int32_t spare_size; /**
- PLATFORM_DEVHANDLE handle; /**
- int32_t bboffset; /**
- uint32_t column; /**
- uint32_t flags; /**
- void *internal; /**
- uint8_t *bblist; /**
- } PLATFORM_DEVICE_info;
复制代码
2.基于platform打开EEPROM platform_device_open(PLATFORM_DEVID_EEPROM50, 0)
- if (deviceid == PLATFORM_DEVID_EEPROM50) {
- /* Store the open flags */
- gDeviceEeprom0.flags = flags;
- evmI2CInit();
- p_info = &gDeviceEeprom0;
- p_info->handle = deviceid;
- return p_info;
- }
复制代码
3.初始化EEPROM evmI2CInit();
- void evmI2CInit(void)
- {
- // Set I2C in reset
- I2CR->ICMDR &= (~CSL_I2C_ICMDR_IRS_MASK);
- platform_delaycycles(100);
-
- // Set Own Address
- I2CR->ICOAR = I2C_OWN_ADDR;
-
- // Set Default I2C High and Low Clock Hold
- I2CR->ICPSC = I2C_PRESCALER;
- I2CR->ICCLKL = I2C_CLK_LOW;
- I2CR->ICCLKH = I2C_CLK_HIGH;
-
- // Enable the Xmt, Master Mode
- I2CR->ICMDR = ( CSL_I2C_ICMDR_MST_MASK |
- CSL_I2C_ICMDR_TRX_MASK |
- CSL_I2C_ICMDR_FREE_MASK );
-
- // Take I2C Out of Reset
- I2CR->ICMDR |= CSL_I2C_ICMDR_IRS_MASK;
- platform_delaycycles(100);
- }
复制代码
4.基于platform写入EEPROM platform_device_write(p_device->handle, 0, test_buf, 12)
- if (deviceid == PLATFORM_DEVID_EEPROM50) {
- if (i2cEepromWriteByteAddr(offset, 0x50, buf, len, I2C_RELEASE_BUS) != I2C_RET_OK) {
- IFPRINT(platform_write("platform_device_write: EEPROM write for address 0x%x failedn", 0x50));
- platform_errno = PLATFORM_ERRNO_EEPROM;
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- return Platform_EOK;
- }
复制代码
5.EEPROM写入 i2cEepromWriteByteAddr(offset, 0x50, buf, len, I2C_RELEASE_BUS)
- I2C_RET i2cEepromWriteByteAddr( uint32_t byte_addr, uint16_t uchEepromI2cAddress, uint8_t *puiData,
- uint32_t uiNumBytes, uint32_t uiEndBusState)
- {
- uint32_t uiBytesWritten, uiBlockCount, uiByteNum, uiCount, uiSizeBytes, uiAddress;
- I2C_RET iret;
- uiSizeBytes = uiNumBytes;
- uiAddress = byte_addr;
- uiByteNum = 0;
- uiBytesWritten = 0;
- /* Block the data into 64 byte blocks, perform a write */
- do{
- /* Get the number of bytes in the current block */
- uiBlockCount = uiSizeBytes - uiBytesWritten;
- if (uiBlockCount > 64)
- uiBlockCount = 64;
- if (uiBlockCount == 0)
- break;
- for (uiCount = 0; uiCount < (uiBlockCount+3)>>2; uiCount++)
- {
- gI2cBlock[uiCount+1] = (puiData[uiByteNum] << 24) | (puiData[uiByteNum+1] << 16) | (puiData[uiByteNum+2] << 8) | (puiData[uiByteNum+3]);
- uiByteNum += 4;
- }
- gI2cBlock[0] = uiAddress;
- iret = i2cEepromWriteBlock(uchEepromI2cAddress, gI2cBlock, uiBlockCount+2, uiEndBusState);
- if (iret != I2C_RET_OK)
- return (iret);
- i2cDelay(0x100);
- uiBytesWritten = uiBytesWritten + uiBlockCount;
- uiAddress = uiAddress + uiBlockCount;
- }while (uiBlockCount);
- return (I2C_RET_OK);
- }
复制代码
以上参考 Inter-Integrated Circuit (I2C) for KeyStone Devices User's Guide.pdf
1
|
|
|
|