AnsweredAssumed Answered

BASIC GPIO

Question asked by delos_reyes.kristian on Jan 17, 2013
Latest reply on Jan 18, 2013 by delos_reyes.kristian
Hi Guys,

I am 1week old to stm32 programming I came from PIC

1ST QUESTION

// FROM Pic Basic Code normally I do this

TrisC = %11111111
int data = PortC
the return is the decimal equivalent of the binary or port C example 1000001 data will contain 65 then that is very easy to manipulate if you want to send via USART / LCD



//00: General purpose output push-pull
//01: Output mode, max speed 10 MHz.

 GPIOC->CRL = 0x11111111;
 GPIOC->CRH = 0x11111111;

//10: Input with pull-up / pull-down
//00: Input mode (reset state)
// set as pulldown
  GPIOA->CRL = 0x88888888;
  GPIOA->CRH = 0x88888888;
  GPIOA->ODR = 0x0000;

while(1)
{
    GPIOC->BSRR |= GPIO_ReadInputData(GPIOA);  //read pins and set PORTC from data of PORTA
    GPIOC->BRR |= GPIO_ReadInputData(GPIOA);  //reset portC based from portA
}

this is working but i want to convert the data to 8 bit to represent an ascii
i want a concept that is similar to this
int data = GPIO_ReadInputData(GPIOA);

instead of doing this:
if (GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6) == 1)
    {
     data +=64
   }
(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_5) == 1)
    {
     data +=32
   }
(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_4) == 1)
    {
     data +=16
   }

2ND QUESTION
usually in PIC to declare a input and output
I DO THIS
TRISA = %11110000 //1111input 0000output so port0-port3(output) port4-port7(input)

so in STM32VL for example i want port A0 - portA7 as output and the rest A8-AX as input how do i do that?



Outcomes