cancel
Showing results for 
Search instead for 
Did you mean: 

STM8s i2c

yussi koske
Associate II
Posted on February 18, 2017 at 11:46

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 );

}
4 REPLIES 4
S.Ma
Principal
Posted on February 18, 2017 at 18:17

Until someone figure it out, try to use SW bit bang IO I2C.

Posted on February 19, 2017 at 14:34

Actually i hoped i could avoid doing so. But if no one got any idea what i'm doing wrong, i guess bit banging it is. Still hope dies last!

Posted on February 20, 2017 at 08:31

Here is a sample source code compatible with STM8/STM32 I2C bitbang IO. Depending on the MCU, choose the right SW NOP delay and the right way to configure the GPIOs.

https://community.st.com/0D50X00009XkW1mSAF

Posted on February 20, 2017 at 09:58

Thanks a lot! As soon as i find time for adopting the code for the STM8S i will provide the code.