From bfa791f6f288fd2cecc5d9088c3a2e3ea208df37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Tue, 7 Feb 2017 11:11:54 +0100 Subject: [PATCH] use I2C with push pull and split transmission (still not working though) --- lib/led_tm1637.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/led_tm1637.c b/lib/led_tm1637.c index 3c2c1db..e808f1d 100644 --- a/lib/led_tm1637.c +++ b/lib/led_tm1637.c @@ -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;