Initialize the I2C bus of the EEPROM. Organize related macros neatly.
This commit is contained in:
@@ -1,29 +1,36 @@
|
||||
#ifndef __I2C_H__
|
||||
#define __I2C_H__
|
||||
|
||||
#define I2C_MAIN_BUS_SDA_PORT PORTD
|
||||
#define I2C_MAIN_BUS_SDA_CLOCK kCLOCK_PortD
|
||||
#define I2C_MAIN_BUS_SDA_PIN 3
|
||||
// Macros:
|
||||
|
||||
#define I2C_MAIN_BUS_SCL_PORT PORTD
|
||||
#define I2C_MAIN_BUS_SCL_CLOCK kCLOCK_PortD
|
||||
#define I2C_MAIN_BUS_SCL_PIN 2
|
||||
// Main bus
|
||||
|
||||
#define I2C_EEPROM_BUS_SDA_PORT PORTC
|
||||
#define I2C_EEPROM_BUS_SDA_CLOCK kCLOCK_PortC
|
||||
#define I2C_EEPROM_BUS_SDA_PIN 11
|
||||
#define I2C_MAIN_BUS_BASEADDR I2C0
|
||||
#define I2C_MASTER_BUS_CLK_SRC I2C0_CLK_SRC
|
||||
#define I2C_MAIN_BUS_BAUD_RATE 100000 // 100 kHz works even with a 20 meter long bridge cable.
|
||||
#define I2C_MAIN_BUS_MUX kPORT_MuxAlt7
|
||||
|
||||
#define I2C_EEPROM_BUS_SCL_PORT PORTC
|
||||
#define I2C_EEPROM_BUS_SCL_CLOCK kCLOCK_PortD
|
||||
#define I2C_EEPROM_BUS_SCL_PIN 10
|
||||
#define I2C_MAIN_BUS_SDA_PORT PORTD
|
||||
#define I2C_MAIN_BUS_SDA_CLOCK kCLOCK_PortD
|
||||
#define I2C_MAIN_BUS_SDA_PIN 3
|
||||
|
||||
#define I2C_MAIN_BUS_BASEADDR I2C0
|
||||
#define I2C_EEPROM_BUS_BASEADDR I2C1
|
||||
#define I2C_MAIN_BUS_SCL_PORT PORTD
|
||||
#define I2C_MAIN_BUS_SCL_CLOCK kCLOCK_PortD
|
||||
#define I2C_MAIN_BUS_SCL_PIN 2
|
||||
|
||||
#define I2C_MAIN_BUS_BAUD_RATE 100000
|
||||
#define I2C_EEPROM_BUS_BAUD_RATE 1000000
|
||||
// EEPROM bus
|
||||
|
||||
#define I2C_MASTER_BUS_CLK_SRC I2C0_CLK_SRC
|
||||
#define I2C_EEPROM_BUS_CLK_SRC I2C1_CLK_SRC
|
||||
#define I2C_EEPROM_BUS_BASEADDR I2C1
|
||||
#define I2C_EEPROM_BUS_CLK_SRC I2C1_CLK_SRC
|
||||
#define I2C_EEPROM_BUS_BAUD_RATE 1000000 // 1 Mhz is the maximum speed of the EEPROM.
|
||||
#define I2C_EEPROM_BUS_MUX kPORT_MuxAlt2
|
||||
|
||||
#define I2C_EEPROM_BUS_SDA_PORT PORTC
|
||||
#define I2C_EEPROM_BUS_SDA_CLOCK kCLOCK_PortC
|
||||
#define I2C_EEPROM_BUS_SDA_PIN 11
|
||||
|
||||
#define I2C_EEPROM_BUS_SCL_PORT PORTC
|
||||
#define I2C_EEPROM_BUS_SCL_CLOCK kCLOCK_PortC
|
||||
#define I2C_EEPROM_BUS_SCL_PIN 10
|
||||
|
||||
#endif
|
||||
|
||||
@@ -8,22 +8,38 @@
|
||||
void InitI2c() {
|
||||
port_pin_config_t pinConfig = {
|
||||
.pullSelect = kPORT_PullUp,
|
||||
.openDrainEnable = kPORT_OpenDrainEnable,
|
||||
.mux = kPORT_MuxAlt7
|
||||
.openDrainEnable = kPORT_OpenDrainEnable
|
||||
};
|
||||
|
||||
i2c_master_config_t masterConfig;
|
||||
I2C_MasterGetDefaultConfig(&masterConfig);
|
||||
uint32_t sourceClock;
|
||||
|
||||
// Initialize main bus
|
||||
|
||||
CLOCK_EnableClock(I2C_MAIN_BUS_SDA_CLOCK);
|
||||
CLOCK_EnableClock(I2C_MAIN_BUS_SCL_CLOCK);
|
||||
|
||||
pinConfig.mux = I2C_MAIN_BUS_MUX;
|
||||
PORT_SetPinConfig(I2C_MAIN_BUS_SDA_PORT, I2C_MAIN_BUS_SDA_PIN, &pinConfig);
|
||||
PORT_SetPinConfig(I2C_MAIN_BUS_SCL_PORT, I2C_MAIN_BUS_SCL_PIN, &pinConfig);
|
||||
|
||||
i2c_master_config_t masterConfig;
|
||||
I2C_MasterGetDefaultConfig(&masterConfig);
|
||||
|
||||
masterConfig.baudRate_Bps = I2C_MAIN_BUS_BAUD_RATE;
|
||||
uint32_t sourceClock = CLOCK_GetFreq(I2C_MASTER_BUS_CLK_SRC);
|
||||
sourceClock = CLOCK_GetFreq(I2C_MASTER_BUS_CLK_SRC);
|
||||
I2C_MasterInit(I2C_MAIN_BUS_BASEADDR, &masterConfig, sourceClock);
|
||||
|
||||
// Initialize EEPROM bus
|
||||
|
||||
CLOCK_EnableClock(I2C_EEPROM_BUS_SDA_CLOCK);
|
||||
CLOCK_EnableClock(I2C_EEPROM_BUS_SCL_CLOCK);
|
||||
|
||||
pinConfig.mux = I2C_EEPROM_BUS_MUX;
|
||||
PORT_SetPinConfig(I2C_EEPROM_BUS_SDA_PORT, I2C_EEPROM_BUS_SDA_PIN, &pinConfig);
|
||||
PORT_SetPinConfig(I2C_EEPROM_BUS_SCL_PORT, I2C_EEPROM_BUS_SCL_PIN, &pinConfig);
|
||||
|
||||
masterConfig.baudRate_Bps = I2C_EEPROM_BUS_BAUD_RATE;
|
||||
sourceClock = CLOCK_GetFreq(I2C_EEPROM_BUS_CLK_SRC);
|
||||
I2C_MasterInit(I2C_EEPROM_BUS_BASEADDR, &masterConfig, sourceClock);
|
||||
}
|
||||
|
||||
void InitPeripherials(void)
|
||||
|
||||
Reference in New Issue
Block a user