Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


You are viewing a reply to GPIO Toggle Question  

GPIO Toggle Question

The reason I want to do it manually, is because in the datasheet for the STA013 Decoder, I’m told to create a start condition, where it is “identified by a high to low transition of the data bus SDA signal while the clock signal SCL is stable in the high state. A START condition must precede any command for data transfer.”

I don’t think that the i2c peripheral does that exact mechanic by itself, correct?

This START condition is standard i2c behavior and so the i2c peripheral should do this in exactly that way you described by itself!

See attached file! :-)

Bab

Really appreciate the help Bab! Now, that the start condition is clarified, this leads me to my next objective. I’m supposed to read from the device. The register 0x01 should have the value 0xAC as an ACK to let me know that the STA013 decoder is present. I used both:

HAL_I2C_Master_Receive(&hi2c3, reg, &data, 1, 100);
&
HAL_I2C_Mem_Read(&hi2c3, 0x86, reg, I2C_MEMADD_SIZE_8BIT, &data, 1, 10);

With reg having the value of 0x01. But, neither of those returned back the correct value. Do you know which of the two functions is the correct one? And do you see anything wrong in what I wrote?

Hey,

I haven’t used the Hal library much. But i think the HAL_IC2_Master_Receive function just sends the address and then records size bytes.
This is useful for devices with a 2 step readout. In the first transmission you would tell the device which register you want to read and in the second transmission you would use this function.

And i think HAL_I2C_Mem_Read would first send the address, then the register you want to read and then record size bytes in a consecutive transmission.

Can’t get more information from the usermanual and i haven’t really worked with the i2c and the HAL so you better dont rely on me!

I hope someone else can help you!

Bab

I feel like I’m asking the wrong question. Here’s the psuedo code of what I’m trying to accomplish:

  • Start Condition
  • Send A Byte The value is 0x86 (134). The seven most significant bits instruct the STA013 to listen (because there may be other chips connected to SDA and SCL). The LSB is clear, telling the STA013 that will will be writing an address.
  • Send A Byte The value is the address where we need to read data. The main program will pass the address to our sta013_read function.
  • Stop Condition
  • Start Condition
  • Send A Byte The value is 0x87 (135). Again, the upper bits select the STA013, and the LSB sets up the next access to read.
  • Receive A Byte Read the byte from the STA013. This will be returned to the main program.
  • Stop Condition


My code looks like this:

uint8_t sta013ReadReg(uint8_t reg)
{
uint8_t data;

// STA_I2C_DEV = 0x86
sta013WriteReg(STA_I2C_DEV, data);
sta013WriteReg((STA_I2C_DEV+1), data);

/* Not sure which of these two is correct verstion */
//HAL_I2C_Mem_Read(&hi2c3, STA_I2C_DEV, reg, I2C_MEMADD_SIZE_8BIT, &data, 1, 10);
//HAL_I2C_Master_Receive(&hi2c3, reg, &data, 1, 100);

return data;
}

I feel like I’m missing this step:

  • Send A Byte The value is the address where we need to read data. The main program will pass the address to our sta013_read function.


Not really sure what it means or how to implement it.