Go to the source code of this file.
Macros | |
#define | I2C_H |
#define | I2C_SLAVE_DEVICE_NO_START_EN 0 |
Enumerations | |
enum | I2C_GPIO_GroupTypeDef { I2C_GPIO_GROUP_A3A4, I2C_GPIO_GROUP_B6D7, I2C_GPIO_GROUP_C0C1, I2C_GPIO_GROUP_C2C3 } |
select pin as SDA and SCL of i2c More... | |
enum | I2C_SlaveMode { I2C_SLAVE_DMA = 0, I2C_SLAVE_MAP } |
select i2c slave mode: DMA and MAPPING More... | |
Functions | |
static void | reset_i2c_moudle (void) |
This function reset I2C module. More... | |
static void | i2c_set_id (unsigned char SlaveID) |
This function serves to set id of I2C module. More... | |
static void | i2c_slave_mapping_mode_data_buffer_config (unsigned char *pMapBuf) |
This function servers to config i2c data buffer in slave mode. More... | |
void | i2c_gpio_set (I2C_GPIO_GroupTypeDef i2c_pin_group) |
This function serves to select a pin port for I2C interface. More... | |
void | i2c_master_init (unsigned char SlaveID, unsigned char DivClock) |
This function serves to set the id of slave device and the speed of I2C interface note: the param ID contain the bit of writting or reading. eg:the parameter 0x5C. the reading will be 0x5D and writting 0x5C. More... | |
void | i2c_slave_init (unsigned char device_ID, I2C_SlaveMode mode, unsigned char *pMapBuf) |
This function serves to set the ID and mode of slave device. More... | |
void | i2c_write_byte (unsigned int Addr, unsigned int AddrLen, unsigned char Data) |
This function serves to write one byte to the slave device at the specified address. More... | |
unsigned char | i2c_read_byte (unsigned int Addr, unsigned int AddrLen) |
This function serves to read one byte from the slave device at the specified address. More... | |
void | i2c_write_series (unsigned int Addr, unsigned int AddrLen, unsigned char *dataBuf, int dataLen) |
This function serves to write a packet of data to the specified address of slave device. More... | |
void | i2c_read_series (unsigned int Addr, unsigned int AddrLen, unsigned char *dataBuf, int dataLen) |
This function serves to read a packet of data from the specified address of slave device. More... | |
#define I2C_H |
#define I2C_SLAVE_DEVICE_NO_START_EN 0 |
enum I2C_SlaveMode |
select i2c slave mode: DMA and MAPPING
dma mode: all sram(64k area form 0x40000~0x4ffff, address 3 byte) could be used for reading or writing data buffer, i2c master just need send sram address(3 byte) on i2c bus in i2c reading or writing, reading/writing sram address could be anywhere and could be different. i2c master timing is: 1.master write: start + device_id(W) + address2+ address1 + address0 + data(1,2...n byte) + stop 2.master read: start + device_id(W) + address2+ address1 + address0 + start + device_id(R) + data(1,2...n byte) + stop
mapping mode: i2c slave data buffer sram could be configured by function: void i2c_slave_mapping_mode_data_buffer_config(unsigned char * pMapBuf), and it is also configured in function: void i2c_slave_init(unsigned char device_ID,I2C_SlaveMode mode,unsigned char * pMapBuf) reading/writing data buffer configured by pMapBuf addressed in core_e1/e2/e3, for i2c master: writing data buffer is pMapBuf,and reading data buffer is (pMapBuf+64) (this offset 64 is managed by MCU hardware, user can not change it)
i2c master no need send any address when reading or writing data, which means i2c master timing is: 1.master write: start + device_id(W) + data(1,2...n byte) + stop 2.master read: start + device_id(W) + start + device_id(R) + data(1,2...n byte) + stop
Enumerator | |
---|---|
I2C_SLAVE_DMA | |
I2C_SLAVE_MAP |
|
inlinestatic |
This function reset I2C module.
[in] | none |
|
inlinestatic |
This function serves to set id of I2C module.
[in] | SlaveID | - this id is fixed id for slave device.For master device, this id is set to access different slave devices. |
|
inlinestatic |
This function servers to config i2c data buffer in slave mode.
[in] | pMapBuf | - to store the buffer data. |
void i2c_gpio_set | ( | I2C_GPIO_GroupTypeDef | i2c_pin_group | ) |
This function serves to select a pin port for I2C interface.
[in] | i2c_pin_group | - the pin port selected as I2C interface pin port. |
void i2c_master_init | ( | unsigned char | SlaveID, |
unsigned char | DivClock | ||
) |
This function serves to set the id of slave device and the speed of I2C interface note: the param ID contain the bit of writting or reading. eg:the parameter 0x5C. the reading will be 0x5D and writting 0x5C.
[in] | SlaveID | - the id of slave device.it contains write or read bit,the lsb is write or read bit. ID|0x01 indicate read. ID&0xfe indicate write. |
[in] | DivClock | - the division factor of I2C clock, I2C clock = System clock / (4*DivClock);if the datasheet you look at is 2*,pls modify it. |
void i2c_slave_init | ( | unsigned char | device_ID, |
I2C_SlaveMode | mode, | ||
unsigned char * | pMapBuf | ||
) |
This function serves to set the ID and mode of slave device.
[in] | device_ID | - it contains write or read bit,the lsb is write or read bit. ID|0x01 indicate read. ID&0xfe indicate write. |
[in] | mode | - set slave mode. slave has two modes, one is DMA mode, the other is MAPPING mode. |
[in] | pMapBuf | - if slave mode is MAPPING, set the first address of buffer master write or read slave. |
void i2c_write_byte | ( | unsigned int | Addr, |
unsigned int | AddrLen, | ||
unsigned char | Data | ||
) |
This function serves to write one byte to the slave device at the specified address.
[in] | Addr | - i2c slave address where the one byte data will be written |
[in] | AddrLen | - length in byte of the address, which makes this function is compatible for slave device with both one-byte address and two-byte address |
[in] | Data | - the one byte data will be written via I2C interface |
unsigned char i2c_read_byte | ( | unsigned int | Addr, |
unsigned int | AddrLen | ||
) |
This function serves to read one byte from the slave device at the specified address.
[in] | Addr | - i2c slave address where the one byte data will be read |
[in] | AddrLen | - length in byte of the address, which makes this function is compatible for slave device with both one-byte address and two-byte address |
void i2c_write_series | ( | unsigned int | Addr, |
unsigned int | AddrLen, | ||
unsigned char * | dataBuf, | ||
int | dataLen | ||
) |
This function serves to write a packet of data to the specified address of slave device.
[in] | Addr | - the register that master write data to slave in. support one byte and two bytes. i.e param2 AddrLen may be 1 or 2. |
[in] | AddrLen | - the length of register. enum 0 or 1 or 2 or 3. based on the spec of i2c slave. |
[in] | dataBuf | - the first SRAM buffer address to write data to slave in. |
[in] | dataLen | - the length of data master write to slave. |
void i2c_read_series | ( | unsigned int | Addr, |
unsigned int | AddrLen, | ||
unsigned char * | dataBuf, | ||
int | dataLen | ||
) |
This function serves to read a packet of data from the specified address of slave device.
[in] | Addr | - the register master read data from slave in. support one byte and two bytes. |
[in] | AddrLen | - the length of register. enum 0 or 1 or 2 or 3 based on the spec of i2c slave. |
[in] | dataBuf | - the first address of SRAM buffer master store data in. |
[in] | dataLen | - the length of data master read from slave. |