Skip to main content
Gbasi.1
Associate III
May 25, 2020
Question

hi, I am trying to use it in the same pin for two different purposes. I'm setting 4 pins for SPI comm and after I finish using them as SPIpins I need them as normal gpio. I tried to toggle them with set and reset but didn't go so well. what should I

  • May 25, 2020
  • 3 replies
  • 862 views

for exmple, this is a part of the code:

void DAC_AD5621_Write ( uint64_t DAC_Data)

{

HAL_GPIO_WritePin(dac_cs_GPIO_Port, dac_cs_Pin, GPIO_PIN_RESET);////Select SPI

DAC_Data = (DAC_Data&0x0FFF)<<2 ;

uint8_t DAC_Data1= (uint8_t)((DAC_Data>>8)&0x00FF);

uint8_t DAC_Data2= (uint8_t)(DAC_Data&0x00FF);

HAL_SPI_Transmit(&hspi1,DAC_Data1,10,100);

HAL_SPI_Transmit(&hspi1,DAC_Data2,10,100);

HAL_GPIO_WritePin(dac_cs_GPIO_Port, dac_cs_Pin, GPIO_PIN_SET);//Deselect SPI

}

while (1)

 {

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,GPIO_PIN_RESET);

 delay_1u(10);

 HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5,GPIO_PIN_SET);

}

This topic has been closed for replies.

3 replies

TDK
May 25, 2020

Initialize them as GPIO output pins after using them as SPI. If they're still in AF mode, output level will be ignored.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Gbasi.1
Gbasi.1Author
Associate III
May 27, 2020

hi, thank you for help.

can you sharpen the concept "AF mode"?

JGerb
Associate II
May 25, 2020

You may just be able to change the MODER register to change them from AF (Alternate Function) to input or output mode, using MODIFY_REG(GPIOA->MODER,***,yyy) where *** is a suitable mask to turn those bits off, and yyy are bits to set in the register. Replace GPIOA with the I/O bank you are using - e.g. GPIOA/B/C etc.

TDK
May 27, 2020

> can you sharpen the concept "AF mode"?

Look up alternate function mode in the reference manual.

"If you feel a post has answered your question, please click ""Accept as Solution""."