0
\$\begingroup\$

This is my code:

#include "stm32f10x.h"
#include "core_cm3.h"
#include "custom.h"
//#include "LCD-HD44780.h"

//int i;
int main(void)
{
    RCC->APB2ENR |= BIT3;

    GPIOB->CRH   |= BIT0 || BIT1;
    GPIOB->CRH   &= ~BIT2 && ~BIT3;
    GPIOB->BSRR  |= BIT8;

    GPIOB->CRH   |= BIT4 || BIT5;
    GPIOB->CRH   &= ~BIT6 && ~BIT7;
    GPIOB->BSRR  |= BIT9;   

    while (1)
    {
    }
}

custom.h file:

#include <stdint.h>
#define BIT0  (uint32_t)0x1
#define BIT1  (uint32_t)0x2
#define BIT2  (uint32_t)0x4
#define BIT3  (uint32_t)0x8
#define BIT4  (uint32_t)0x10
#define BIT5  (uint32_t)0x20
#define BIT6  (uint32_t)0x40
#define BIT7  (uint32_t)0x80
#define BIT8  (uint32_t)0x100
#define BIT9  (uint32_t)0x200
#define BIT10 (uint32_t)0x400
#define BIT11 (uint32_t)0x800
#define BIT12 (uint32_t)0x1000
#define BIT13 (uint32_t)0x2000
#define BIT14 (uint32_t)0x4000
#define BIT15 (uint32_t)0x8000
#define BIT16 (uint32_t)0x10000
#define BIT17 (uint32_t)0x20000
#define BIT18 (uint32_t)0x40000
#define BIT19 (uint32_t)0x80000
#define BIT20 (uint32_t)0x100000
#define BIT21 (uint32_t)0x200000
#define BIT22 (uint32_t)0x400000
#define BIT23 (uint32_t)0x800000
#define BIT24 (uint32_t)0x1000000
#define BIT25 (uint32_t)0x2000000
#define BIT26 (uint32_t)0x4000000
#define BIT27 (uint32_t)0x8000000
#define BIT28 (uint32_t)0x10000000
#define BIT29 (uint32_t)0x20000000
#define BIT30 (uint32_t)0x40000000
#define BIT31 (uint32_t)0x80000000

LED on Pin 8 turns on But in Pin 9 does not!. and This all of code I wrote. I cant find out where is problem.

\$\endgroup\$
  • \$\begingroup\$ Where you set GPIOB->CRH you have "&&" in two of the lines. Change them to just "&". The "&&" operation is the logical AND, the "&" is the bitwise AND. \$\endgroup\$ – Finbarr May 16 '17 at 11:03
4
\$\begingroup\$

You have two lines of code where you set GPIOB->CRH:

GPIOB->CRH   &= ~BIT2 && ~BIT3;

GPIOB->CRH   &= ~BIT6 && ~BIT7;

The && operator is the logical AND, which returns true or false. What you need to use here is the & operator, which is the bitwise AND.

The same applies to the logical OR operator || and the bitwise OR | in the other lines of code.

\$\endgroup\$
  • 2
    \$\begingroup\$ Same goes for || it should be |. \$\endgroup\$ – Bence Kaulics May 16 '17 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.