2022-03-17 12:30 AM
I am trying to get I2C working for STM8S003F3P6 with ESP8266. I tried I2C sample code available with standard periferal library https://www.st.com/en/embedded-software/stsw-stm8069.html . But for some reason I2c is not working. Now I just noticed the I2C pins PB4 and PB5 marked as open drain without any protection. So I wanted to check if I bricked these pins during my earlier testing sessions. So I written simple code to output on PB4,PB5 pins below, but I am not getting voltage on the PB4 and PB5 pin. I am getting correct output on PD4
static inline void delay_ms(uint16_t ms) {
uint32_t i;
for (i = 0; i < ((F_CPU / 18000UL) * ms); i++)
__asm__("nop");
}
#define LED1_GPIO_PORT (GPIOB)
#define LED1_GPIO_PINS (GPIO_PIN_4 | GPIO_PIN_5)
#define LED2_GPIO_PORT (GPIOD)
#define LED2_GPIO_PINS (GPIO_PIN_4)
void main(void)
{
/* Initialize I/Os in Output Mode */
GPIO_Init(LED1_GPIO_PORT, (GPIO_Pin_TypeDef)LED1_GPIO_PINS, GPIO_MODE_OUT_OD_HIZ_SLOW);
GPIO_Init(LED2_GPIO_PORT, (GPIO_Pin_TypeDef)LED2_GPIO_PINS, GPIO_MODE_OUT_PP_LOW_FAST);
//char ans;
/* system_clock / 1 */
CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
/* Initialize LEDs mounted on STM8/128-EVAL board */
//STM_EVAL_LEDInit(LED2);
// STM_EVAL_LEDOff(LED2);
UART1_DeInit();
/* UART1 configuration ------------------------------------------------------*/
/* UART1 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
- UART1 Clock disabled
*/
UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO,
UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
uint8_t counter = 0;
while (1)
{
//ans = getchar();
//printf("%c", ans);
printf("Test, %d\n", counter++);
/* toggle pin every 2000ms */
GPIO_WriteReverse(LED1_GPIO_PORT, (GPIO_Pin_TypeDef)LED1_GPIO_PINS);
GPIO_WriteReverse(LED2_GPIO_PORT, (GPIO_Pin_TypeDef)LED2_GPIO_PINS);
delay_ms(2000);
}
}
Below is the circuit diagram
I am using above circuit, I have pulled up PB4 and PB5 as these are open drain pins. I am measuring output from PB4 and PB5 pins and ground.
Can someone help if above setup is correct and if not how to check if PB4 and PB5 are not broken