use I2C with push pull and split transmission (still not working though)

This commit is contained in:
King Kévin 2017-02-07 11:11:54 +01:00
parent 76b2889334
commit bfa791f6f2
1 changed files with 6 additions and 4 deletions

View File

@ -58,8 +58,8 @@ void led_tm1637_setup(void)
// configure GPIO for I2C peripheral (this cause a small low pulse on the lines, but I didn't figure out why)
rcc_periph_clock_enable(RCC_AFIO); // enable clock for alternate function
rcc_periph_clock_enable(RCC_I2C_PORT(LED_TM1637_I2C)); // all I2C pin are on port B
gpio_set_mode(I2C_SCL_PORT(LED_TM1637_I2C), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, I2C_SCL_PIN(LED_TM1637_I2C)); // clock line will be an output since we will be master
gpio_set_mode(I2C_SDA_PORT(LED_TM1637_I2C), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, I2C_SDA_PIN(LED_TM1637_I2C)); // data line will be an output since we will be master
gpio_set_mode(I2C_SCL_PORT(LED_TM1637_I2C), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, I2C_SCL_PIN(LED_TM1637_I2C)); // clock line will be an output since we will be master
gpio_set_mode(I2C_SDA_PORT(LED_TM1637_I2C), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, I2C_SDA_PIN(LED_TM1637_I2C)); // data line will be an output since we will be master
// configure I2C peripheral
rcc_periph_clock_enable(RCC_I2C(LED_TM1637_I2C)); // enable clock for I2C peripheral
@ -147,9 +147,11 @@ bool led_tm1637_number(uint16_t number)
(void) number;
bool to_return = false; // result to return
const uint8_t write_data[] = { 0x40 }; // command: write data, automatic address adding, normal
uint8_t data[] = { 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }; // set address C0H and add data
uint8_t data_0[] = { 0xc0, 0x00, 0xff }; // set address C0H and add data
uint8_t data_2[] = { 0xc2, 0x00, 0xff };
uint8_t data_4[] = { 0xc4, 0x00, 0xff };
if (led_tm1637_write(write_data,LENGTH(write_data)) && led_tm1637_write(data,LENGTH(data))) { // send commands
if (led_tm1637_write(write_data,LENGTH(write_data)) && led_tm1637_write(data_0,LENGTH(data_0)) && led_tm1637_write(data_2,LENGTH(data_2)) && led_tm1637_write(data_4,LENGTH(data_4))) { // send commands
to_return = true;
}
return to_return;