cancel
Showing results for 
Search instead for 
Did you mean: 

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 do

Gbasi.1
Associate II

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);

}

4 REPLIES 4
TDK
Guru

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".
JGerb
Associate III

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.

hi, thank you for help.

can you sharpen the concept "AF mode"?

TDK
Guru

> 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".