2014-02-03

CooCox I2C read/write EEPROM example program

Coocox I2C master transfer example - 2014feb0301

/**
  ***************************************************************************** 
  * @title   Master_Transfer.c
  * @author  CooCox
  * @date    11 Oct 2010
  * @brief   This example describes how to configure I2C working in master mo
  *          de,
  *          and Read/Write EEPROM using I2C bus.
  *******************************************************************************
  */
////// The above comment is automatically generated by CoIDE ///////////////////

#include "lpc11xx_syscon.h"
#include "lpc11xx_i2c.h"

/*
 * I2C Master Mode Transfer Example
 */
void I2CMasterExp()
{
unsigned char send_buf[10] = {0,0, 1,2,3,4,5,6,7};
unsigned char rece_buf[10] = {0};

int i,j;
I2C_M_SETUP_Type transferMCfg; 

/* It seems to be bit0 is for I2C, different from
     * UM. To be retested along with SSP reset. SSP and I2C
     *reset are overlapped, a known bug, for now, both SSP 
     *and I2C use bit 0 for reset enable. */

    SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_I2C, ENABLE);
    SYSCON_PeriphResetCmd(SYSCON_RSTPeriph_I2C, DISABLE);

    I2C_PinsInit(I2CMODE_SF); 
    I2C_Init(LPC_I2C, 100000);  
    I2C_Cmd(LPC_I2C, ENABLE); 
    
    transferMCfg.sl_addr7bit = 0xA0>>1;
transferMCfg.tx_data = send_buf;
transferMCfg.tx_length = 8;
transferMCfg.rx_data = NULL;
transferMCfg.rx_length = 0;
transferMCfg.retransmissions_max = 3;
I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);
    
    for(i=0;i<100;i++) {
        for(j=0;j<1000;j++);
    }
        
    transferMCfg.tx_data = send_buf;
transferMCfg.tx_length = 2;
transferMCfg.rx_data = rece_buf;
transferMCfg.rx_length = 6;
transferMCfg.retransmissions_max = 3;
I2C_MasterTransferData(LPC_I2C, &transferMCfg, I2C_TRANSFER_POLLING);

}

.END

No comments:

Post a Comment