AnsweredAssumed Answered

STM8s i2c

Question asked by koske.yussi on Feb 18, 2017
Latest reply on Feb 20, 2017 by koske.yussi

Hello, 

i can't get my stm8s105c6t6 i2c to work. Hopefully anybody has an idea what i'm diong wrong. i'm pleased for any imput i can get. 

 

here some changed code which doesn't do anything but i just try to measure anything on PORT E.1 &E.2. Unfortunately  the two Pins remain high (i'm using the std library from stm8):

void main(void)
{
//Set Clock
CLK_Config();

 

//Set Ports 
GPIO_Config();

 

I2C_DeInit();

I2C_Init(100000, 0xA0, I2C_DUTYCYCLE_2, I2C_ACK_CURR, I2C_ADDMODE_7BIT, 16);
//I2C->SR3 &=0xFD; //clear busy
I2C_Cmd(ENABLE);

 

while (1) {
I2C_GenerateSTART(ENABLE); // start
I2C_Send7bitAddress(0xD0, I2C_DIRECTION_TX); // address 1101000 + 0 (WRITE)
I2C_SendData(0x00); // set register pointer 00h
I2C_SendData(0x00); // write 0x00 to 00h (oscillator enabled)
I2C_GenerateSTOP(ENABLE);

}
}

 

void CLK_Config(void)
{
CLK_DeInit();
/* Initialization of the clock */
/* Clock divider to HSI/1 */
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
CLK_HSICmd(ENABLE);

 

CLK_PeripheralClockConfig(CLK_PERIPHERAL_I2C,ENABLE);
}


void GPIO_Config(void)
{
//I2C
GPIO_Init(GPIOE, GPIO_PIN_1, GPIO_MODE_OUT_OD_HIZ_FAST );
GPIO_Init(GPIOE, GPIO_PIN_2, GPIO_MODE_OUT_OD_HIZ_FAST );
}

Outcomes