Need help with i2c restart sequence

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Need help with i2c restart sequence

Postby ep.hobbyiest » Wed Jan 10, 2018 3:27 pm

Hi,
I am using latest chibios version and STM32F103xx controller. I want to interface oled ssd1306 display with i2c interface. I got stage where we have to send some commands and the later without stop condition we have to send start condition(Restart condition) and then we have to send data to display.

If i use i2cMasterTransmitTimeout function then it will generate the i2c bus sequence.
following is code snippet i want to convert into chibi i2c format.

Code: Select all

//   OLED_command (ind, 0x21) ;
//   OLED_command (ind, 0x00);
//   OLED_command (ind, 127);
//   OLED_command (ind, 0x22) ;
//   OLED_command (ind, 0x00);
//   OLED_command (ind, 7);
//   i2c_start ();
//   i2c_write (ind) ;
//   i2c_write (0x40) ;
//   for (i = 0; i < 1024; i++)
//   {
//
//      i2c_write (DISPLAY[i]) ;
//   }
//
//   i2c_stop ();


Thanks..

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Need help with i2c restart sequence

Postby tfAteba » Thu Jan 11, 2018 9:35 am

Hello,

I have control this Oled two years ago with an STM32F401 Nucléo board.

To help you here are the base functions that I wrote to control the LCD:

Code: Select all

/**
 * @fn    writeCmd
 * @brief Write a command to the i2c bus for the lcd
 *
 * @param[in] cmd Command to write
 * @return    msg The result of the writing operation
 */
msg_t writeCmd(uint8_t cmd){
  uint8_t command[2];
  uint8_t txLength = sizeof(command)/sizeof(command[0]);
  uint8_t rxLength = 0;
 
  command[0] = 0x00; // Co = 0, D/C = 0
  command[1] = cmd;

  i2cAcquireBus(&I2CD1);
  msg_t msg = i2cMasterTransmitTimeout(&I2CD1, ssd_addr, command, txLength,
      NULL, rxLength, MS2ST(4));
  i2cReleaseBus(&I2CD1);

  return msg;
}

/**
 * @fn    writeData
 * @brief Write the data to the i2C bus for the lcd
 *
 * @param[in] data    Data to send to the lcd
 * @param[in] length  Size of the data to send.
 * @return    msg     The result of the writing operation
 */
msg_t writeData(uint8_t* data, uint16_t length){
  uint8_t command[length+1];
  uint8_t txLength = length+1;
  uint8_t rxLength = 0;

  command[0] = 0x40;       // Co = 0, D/C = 1
  memmove(&command[1], data, length);
 
  i2cAcquireBus (&I2CD1);
  msg_t msg = i2cMasterTransmitTimeout(&I2CD1, ssd_addr, command, txLength,
      NULL, rxLength, MS2ST(10));
  i2cReleaseBus (&I2CD1);

  return msg;
}


The LCD understand command and data so if you have this two functions and the datasheet, you just have to implement the flow chart to control the LCD.

I hope this can help you.
regards,

Theo.

ep.hobbyiest
Posts: 94
Joined: Sun Jun 26, 2016 5:22 pm
Has thanked: 4 times
Been thanked: 1 time

Re: Need help with i2c restart sequence

Postby ep.hobbyiest » Thu Jan 11, 2018 6:08 pm

Thanks tfAteba.
But i am looking for i2c restart condiiton which requires while sending data which to be display.

if i use i2cMasterTransmitTimeout function then it will generate i2c start and i2c stop condition.

could you please share your code for ssd1306 lcd. it will be very helpful.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Need help with i2c restart sequence

Postby tfAteba » Thu Jan 11, 2018 11:19 pm

Hi,

Of course, I will share my code.

Tomorrow, I will make a git repo and send you the link. For the moment, I have it in my old computer locally.

For me using the i2cMasterTransmitTimeout function worked without problem, I could control the LCD and print data on it.

But maybe other I2C function can be used as well :)
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Need help with i2c restart sequence

Postby tfAteba » Fri Jan 12, 2018 10:26 am

Hi,

Here is a link to my git repository where I have pushed my code just a minute ago.
https://github.com/tfateba/stm32f401re-nucleo-ssd1306

The code is not mature yet, you will see there are still a lot to do :) . You feedback is welcome any way.
In this small project, I use an RTC the famous DS1307, a 4 digits 7 segments LCD and an OLED LCD the SSD1306.
With this code, I can Initialize the LCD and print RTC data on it. I can also draw line, control just a pixel and so on.

If you have any other question do not hesitate.
I hope this will help you :)
regards,

Theo.

User avatar
tfAteba
Posts: 547
Joined: Fri Oct 16, 2015 11:03 pm
Location: Strasbourg, France
Has thanked: 91 times
Been thanked: 48 times

Re: Need help with i2c restart sequence

Postby tfAteba » Fri Jan 12, 2018 10:30 am

Ho here is also a photo to show the result :P
Attachments
20180112_001135.jpg
regards,

Theo.


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 26 guests