AnsweredAssumed Answered

STM32F0308 and HTS221 I2C sensor interface

Question asked by Maioli.Francesco on Oct 7, 2015
Hi all, 
I am trying to interface an HTS221 (on a X-NUCLEO board) to the STM32F0 discovery and I cannot get any response. 
In detail, after start generation, the SCA is pulled down as well as the SCL, but the SCL is not starting moving as expected.

The hardware is correct because I tried the XNUCLEO with arduino and it is ok. The micro pins are working properly, and there are 4K7 hw pullups.

This is the INIT code, timing has been calculated by ST excel tool, according to SystemCoreClock = 8Mhz

void HTS221_Init(void)
{
GPIO_InitTypeDef InitGpio;
I2C_InitTypeDef InitI2C;
 
I2C_DeInit(HTS221_I2C);
 
/* I2C1 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);
 
// Enables the clock for I2C PINS
RCC_AHBPeriphClockCmd(I2C_GPIO_CLK, ENABLE);
 
 
//GPIO_PinAFConfig(I2C_PORT, SMBA_PIN, GPIO_AF_1);
 
// Set port configuration
//InitGpio.GPIO_Pin = (SDA_PIN | SCL_PIN | SMBA_PIN);
InitGpio.GPIO_Pin = (SDA_PIN | SCL_PIN);
InitGpio.GPIO_Mode = GPIO_Mode_AF;
InitGpio.GPIO_Speed = GPIO_Speed_Level_1;
InitGpio.GPIO_OType = GPIO_OType_OD;
InitGpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
// Initialises the DOUTS
GPIO_Init(I2C_PORT, &InitGpio);
 
/*Configure GPIO pin alternate function */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);
 
I2C_StructInit(&InitI2C);
InitI2C.I2C_Timing = 0x00201D2B;
InitI2C.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
InitI2C.I2C_DigitalFilter = 0x00;
InitI2C.I2C_Mode = I2C_Mode_I2C;
InitI2C.I2C_OwnAddress1 = 0x01;
InitI2C.I2C_Ack = I2C_Ack_Enable;
InitI2C.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
 
I2C_Init(I2C1, &InitI2C);
 
I2C_Cmd(I2C1, ENABLE);
}

After the first transmission handling function, both SCA and SCL are down and don't move anymore:

uint8_t I2C_RdReg(int8_t Reg, int8_t *Data, uint8_t DCnt)
{
int8_t Cnt, SingleData = 0;
 
while(I2C_GetFlagStatus(HTS221_I2C, I2C_FLAG_BUSY) == SET);
I2C_TransferHandling(HTS221_I2C, HTS221_Addr, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
 
.......

I think that I will have to program a I2C function by software if I cannot solve this... HELP! I am pretty sure that is a stupid issue, but I cannot find it.
Thanks in advance.

Outcomes