0

I am programming the STM8L051F3 processor for a simple application in which it is only necessary to control all GPIO.

The problem is that I can't control the GPIOC pin 0.

I just configured the GPIO registers. Is any other startup necessary?

I also tried to use stm8cubemx on Ubuntu. Software that I found useless because it generates an ioc8 file that has no information on how to use it in Ubuntu.

#include <stdint.h>
#include <string.h>
#include "stm8l.h"

void config_gpio(){
           //76543210
  PA_DDR = 0b00000000;
  PA_CR1 = 0xff;
  PA_CR2 = 0x00;
           //76543210
  PB_DDR = 0b00100110;
  PB_CR1 = 0xff;
  PB_CR2 = 0x00;
           //76543210
  PC_DDR = 0b01110011;
  PC_CR1 = 0xff;
  PC_CR2 = 0x00;
           //76543210
  PD_DDR = 0b00000000;
  PD_CR1 = 0xff;
  PD_CR2 = 0x00;

  PA_ODR = 0x00;
  PB_ODR = 0x00;
  PC_ODR = 0x00;
  PD_ODR = 0x00;
  return;
}

void delay(unsigned long delay){
  unsigned long i = 0;  
  for(i = 0; i < delay; i++) {}
  return;
}

void rotate_left(int steps){
  int n=0; 
  for(n=0; n<steps; n++){
    //PC_DDR = 0b01110011;
               //76543210
    PC_ODR =   0b01100001;
    delay(100);
    PC_ODR =   0b00110001;
    delay(100);
    PC_ODR =   0b00010011;
    delay(100);
    PC_ODR =   0b01000011;
    delay(100);
  }
  return;
}

void rotate_right(int steps){
  int n=0; 
  for(n=0; n<steps; n++){
    //PC_DDR = 0b01110011;
               //76543210
    PC_ODR =   0b01000011;
    delay(100);
    PC_ODR =   0b00010011;
    delay(100);
    PC_ODR =   0b00110001;
    delay(100);
    PC_ODR =   0b01100001;
    delay(100);
  }
  return;
}

int main() {
  config_gpio();

  do {
    delay(7777);

    rotate_right(100);
    rotate_left(100);

  } while(1);
}

Terminal cmd.

Compile sdcc -lstm8 -mstm8 --opt-code-size --std-sdcc99 --nogcse --all-callee-saves --debug --verbose --stack-auto --fverbose-asm --float-reent --no-peep -I./ -I./STM8S_StdPeriph_Driver/inc -D STM8L051 ./main.c

Prog stm8flash -c stlinkv2 -p stm8l051f3 -s flash -w main.ihx

Clifford
  • 88,407
  • 13
  • 85
  • 165
Ilidam
  • 73
  • 6
  • The `rotate_right()` and `rotate_left()` functions never change PC0. What do you expect and what do you observe that tells you it's not working? – kkrambo May 22 '20 at 14:23
  • Hello @kkrambo. I'm measuring the voltage of pin. PC4 I can measure the pulses. The first bit isn't the msb? Why PC0 never changes? – Ilidam May 22 '20 at 20:13
  • @kkrambo. Sorry, I explained myself badly. The problem is that PC0 always has a 0V electrical value. – Ilidam May 22 '20 at 20:20
  • The problem is PC0 and PC1 only work as open drain output. – Ilidam May 22 '20 at 21:00
  • The ioc8 file is the STM8CubeMX project file, not the target code. According to the [user manual](https://www.st.com/resource/en/user_manual/dm00336190-stm8-configuration-tool-stmicroelectronics.pdf) unlike STM32CubeMX, STM8CubeMX does not support code generation. – Clifford May 22 '20 at 23:29

1 Answers1

0

PC0 and PC1 only works as open drain in stm8l051f3.

Ilidam
  • 73
  • 6