2018-01-21 12:54 PM
I have a
STEVAL-STLKT01V1 Sensor Tile. I want to add additional sensing capabilities and was wondering how to add a peripheral that communicates over I2C? Are there any firmware examples of how to do this?
#stm32l4-hal-i2c2018-01-22 02:40 AM
From UM2101, ''Getting started with the STEVAL-STLKT01V1 SensorTile integrated development platform'':
http://www.st.com/resource/en/user_manual/dm00320099.pdf
See:
http://www.st.com/en/evaluation-tools/steval-stlkt01v1.html
Just looks to be a standard I2C connection - so any of the STM32 I2C examples should do?
2018-01-22 08:47 AM
Thanks Andrew for your reply. I was looking at the basic I2C_TwoBoards_ComPolling example from STM32CubeL4 firmware examples but couldn't get it to work. Can you confirm some of the steps?
I2C_ADDRESS - From what I was reading, this should be bit shifted to the left to go from a 7-bit address to 8-bit left justified address? (e.g. I want slave with address 0x04, I would set this as 0x08?)
I2C_TIMING - Not sure how this is calculated so I've been going with the default of 0x00D00E28 from the example. I want the standard 100kbits/s clock rate.
I kept the I2C configurations from the example the same except changed it to 7-bit addressing mode
I2cHandle.Instance = I2Cx;
I2cHandle.Init.Timing = I2C_TIMING; I2cHandle.Init.OwnAddress1 = I2C_ADDRESS; I2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; I2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; I2cHandle.Init.OwnAddress2 = 0xFF; I2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; I2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;After that, defining my transmit and receive buffers, I call
HAL_I2C_Master_Transmit(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t*)aTxBuffer, 3, 10000);
HAL_I2C_Master_Receive(&I2cHandle, (uint16_t)I2C_ADDRESS, (uint8_t *)aRxBuffer, 6, 10000);
However, HAL_I2C_Master_Transmit returns HAL_ERROR. I've added 10k resistors to the SDA and SCL lines to pull it up to 5V.
Any ideas what could be going wrong? Thanks.