[SOLVED] STM32 Nucleo L452RE send I2C

Thread Starter

jozef1990

Joined Aug 6, 2019
8
I have this code...
When I power my micro I can write the string fine, but cannot send anything else to the driver, the driver is getting stuck with "8.8.8.8.8.8." displayed on the screen, what an I do?

C-like:
void vd_I2c1_pcf85134_lcd_display_update(void)

{


u8_i2c1_buffer_tx_index = 0;



  for(uint8_t z = 0  ; z < i2c1_pcf85134_lcd_maximum_command_length; z++)

    u8_i2c1_buffer_tx[z] = 0;



  //Update PCF85134 LCD display data registers

  u8_i2c1_buffer_tx[u8_i2c1_buffer_tx_index++] = i2c1_pcf85134_control_bytes_continue_command;

  u8_i2c1_buffer_tx[u8_i2c1_buffer_tx_index++] = i2c1_pcf85134_command_byte_load_data_pointer;

  u8_i2c1_buffer_tx[u8_i2c1_buffer_tx_index++] = i2c1_pcf85134_control_byte_data;


  bool bl_colon1  = false;

  bool bl_colon2  = false;

  bool bl_null    = false;


  for(uint8_t u8_i = 0, u8_j = i2c1_pcf85134_lcd_maximum_command_length - 2 ; u8_i < display_number_of_digits; u8_i++)

  {

    if(u8_lcd_display_data[u8_i] == '\0')

      bl_null = true;

    if(bl_null)

    {

      u8_i2c1_buffer_tx[u8_j--] = '\0';

      u8_i2c1_buffer_tx_index++;

      if(u8_i2c1_buffer_tx_index == (i2c1_pcf85134_lcd_maximum_command_length - 1))

          break;


    }

    else if(u8_lcd_display_data[u8_i] == '.')

      u8_i2c1_buffer_tx[u8_j] = seg_dp;

    else if(u8_lcd_display_data[u8_i] == ':')

    {

      if(u8_i < 3)

        bl_colon1 = true;

      else

        bl_colon2 = true;

    }

    else //character is for a 7 segment digit

    {


      u8_i2c1_buffer_tx[u8_j--] |= u8_lcd_display_ascii_to_digit_table[u8_lcd_display_data[u8_i]];


      u8_i2c1_buffer_tx_index++;

      if(u8_j < 3)                  // Dont clear u8_i2c1_buffer_tx[2] to [0] pcf85134 command bytes

        break;

      u8_i2c1_buffer_tx[u8_j] = 0;  // Initialise next digit data -@TODO -bug: first encoded character isn't zeroed before ORing

    }

  }

  u8_i2c1_buffer_tx[u8_i2c1_buffer_tx_index++] = (bl_colon1 << seg_colon1) | (bl_colon2 << seg_colon2);

  u8_i2c1_buffer_tx[u8_i2c1_buffer_tx_index++] = 0x00; //Not Used


  //DMA1_Channel6->CNDTR = u8_i2c1_buffer_tx_index + 1;


  HAL_I2C_Master_Transmit(&hi2c1, display_Addr, u8_i2c1_buffer_tx, 32, 100);


}


void WriteString(const std::string& s)

{

  sprintf((char *)u8_lcd_display_data, s.c_str());



  vd_I2c1_pcf85134_lcd_display_update();

  while(I2C1->CR2 & (uint16_t)I2C_IT_BUF);

 

}


int main(void){


WriteString("8.8.8.8.8.8.");


}
 

MrChips

Joined Oct 2, 2009
30,464
I have solved this issue
It is impolite and not the spirit of AAC forums to post an issue and then walk away having solved the issue on your own.
AAC is not only about solving your problem. It is about sharing solutions with others so that they too might benefit from the experience.

Please post what you encountered and did in order to solve the issue.
 

Thread Starter

jozef1990

Joined Aug 6, 2019
8
It is impolite and not the spirit of AAC forums to post an issue and then walk away having solved the issue on your own.
AAC is not only about solving your problem. It is about sharing solutions with others so that they too might benefit from the experience.

Please post what you encountered and did in order to solve the issue.
If I could I would delete the question but I can't, I have asked for it to be deleted.

Essentially, the question was formatted all wrong and I wasn't happy with it.
 

MrChips

Joined Oct 2, 2009
30,464
As a rule, threads and posts are not deleted except in cases where they violate AAC rules.

The request still stands, that you need to state what was wrong and how it was corrected.
 

Thread Starter

jozef1990

Joined Aug 6, 2019
8
As a rule, threads and posts are not deleted except in cases where they violate AAC rules.

The request still stands, that you need to state what was wrong and how it was corrected.
The fix was to make sure that the data length was correct in

HAL_I2C_Master_Transmit(&hi2c1, display_Addr, u8_i2c1_buffer_tx, 32, 100);

32 needed to be 11 which was the correct data length.
 
Top