Salida STM32F4 en PD15 creando una señal PWM no deseada en PD9

        #include "stm32f4xx.h"
        #include "stm32f4xx_hal_def.h"
        #include "stm32f4xx_hal_rcc.h"
        #include "stm32f4xx_hal_gpio.h"

        int main(void) {
        uint32_t  S1S2, S11S12,S21S22,S31S32,S41S42,S51S52,S61S62;
        uint32_t  comp1,notComp1, comp2,notComp2,comp3,notComp3,inj,notInj,ssgn,notSsgn;

          //Define the structure
         GPIO_InitTypeDef GPIO_InitStruct;

//Start the clock on port D
RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;

//Configure the GPIOD OUTPUT pin registers
// port D OUTPUT PIN
GPIO_InitStruct.Pin =
        GPIO_PIN_15  //s1 s2
        | GPIO_PIN_14 //s61 s62
        |GPIO_PIN_13 //s51 s52
        |GPIO_PIN_12  //s41 s42
        |GPIO_PIN_11 //s31 s32
        |GPIO_PIN_10 //s21 s22
        |GPIO_PIN_9; //s11 s12
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_PULLUP;

HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

    //Configure the GPIOD INPUT pin registers
    // Port A INPUT PINs
GPIO_InitStruct.Pin =
GPIO_PIN_15   //COMP 1
|GPIO_PIN_14  //COMP 2
|GPIO_PIN_13; //COMP 3
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

RCC->AHB1ENR |= RCC_AHB1ENR_GPIOBEN;

    //Configure the GPIOD INPUT pin registers
    // port B INPUT PIN
GPIO_InitStruct.Pin =
GPIO_PIN_15 //Ssgn
|GPIO_PIN_14  //Sinj
|GPIO_PIN_13; //Sinj-
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

while (1)
    {
                notInj = ~GPIOB->IDR&GPIO_PIN_14;
                notInj = notInj << 1;
                comp1 = GPIOA->IDR&GPIO_PIN_15;
                notComp1 = ~GPIOA->IDR&GPIO_PIN_15;
                ssgn = GPIOB->IDR&GPIO_PIN_15;
                notSsgn = ~GPIOB->IDR&GPIO_PIN_15;
                comp3 = GPIOA->IDR&GPIO_PIN_13;
                comp3 = comp3 << 2;
                notComp3 = ~GPIOA->IDR&GPIO_PIN_13;
                notComp3 = notComp3 << 2;
                inj =  GPIOB->IDR&GPIO_PIN_14;
                inj = inj << 1;
                comp2 = GPIOA->IDR&GPIO_PIN_14;
                comp2 = comp2 << 1;
                notComp2 = ~GPIOA->IDR&GPIO_PIN_14;
                notComp2 = notComp2 << 1;

 ///////////////S1S2//////////////////////////////////////////////////////////////////////

        S1S2 = notInj;
        GPIOD->ODR = S1S2; //output is now on pin 15
  /////////////////////S11S12////////////////////////////////////////////////////////

        S11S12 = ((comp1&notComp3)&(ssgn&inj)) | ((notComp1&comp3)&(notSsgn&inj));
        S11S12 = S11S12 >> 6;
        GPIOD->ODR = S11S12; //output on pin 9
   }
}

Cuando muestro este código a la placa y conecto el osciloscopio al pin 9, obtengo una señal PWM cuando debería obtener una línea recta para el voltaje de CC si, sin embargo, comento //GPIOD-> ODR = S1S2 obtengo una línea recta en el osciloscopio como debería.

entradas PA15 ALTO, PB15 ALTO y PA13 ALTO todo lo demás bajo.

Si alguien entiende lo que estoy haciendo mal, agradecería una respuesta, gracias de antemano.

debería estar obteniendo una línea recta, no esto. http://imgur.com/gallery/YBWom

¿Puede darnos un ejemplo de código completo?
cosa segura en un segundo

Respuestas (1)

Esto se debe a que una asignación como GPIOD->ODR = valueestablece los 16 bits de puerto a la vez, por lo que cada asignación restablece el bit de puerto que el otro acaba de establecer.

Puede calcular todos los valores de los pines de salida y configurarlos a la vez

S1S2 = notInj;
// will do later : GPIOD->ODR = S1S2; //output is now on pin 15
S11S12 = ((comp1&notComp3)&(ssgn&inj)) | ((notComp1&comp3)&(notSsgn&inj));
S11S12 = S11S12 >> 6;
GPIOD->ODR = S11S12 | S1S2; //output on pin 9 AND 15

o puede enmascarar los valores de bits del puerto

GPIOD->ODR = (GPIOD->ODR & ~GPIO_PIN_15) | S1S2;
// ...
GPIOD->ODR = (GPIOD->ODR & ~GPIO_PIN_9) | S11S12;

o use el registro BSRR para cambiar bits de puerto individuales

GPIOD->BSRR = S1S2 ? (1 << 15) : (1 << (15 + 16));
// ...
GPIOD->BSRR = S11S12 ? (1 << 9) : (1 << (9 + 16));

o averigüe la dirección de banda de bits de los bits del puerto y configúrelos directamente

#define GPIOD_ODR_OFFSET ((uint32_t)&(GPIOD->ODR) - (PERIPH_BASE))
#define GPIOD_ODR_BB (PERIPH_BB_BASE + GPIOD_ODR_OFFSET * 32U)
#define GPIOD_ODR_PIN(x) ((volatile uint32_t *)(GPIO_ODR_BB + (x) * 4))
// calculate S1S2 ...
GPIOD_ODR_PIN(15) = S1S2;
// calculate S11S12 ...
GPIOD_ODR_PIN(9) = S11S12;
Sí, me di cuenta de esto momentos después de publicar esto... jajaja gracias por la respuesta tan detallada, realmente lo aprecio.