Configuration of the SPI Pin

Source: Internet
Author: User

/**spi2 GPIO Configuration
PB12------> Spi2_nss
PB13------> Spi2_sck
PB14------> Spi2_miso
PB15------> Spi2_mosi
*/
Gpio_initstruct.pin = gpio_pin_13| Gpio_pin_15;
Gpio_initstruct.mode = gpio_mode_af_pp;
Gpio_initstruct.speed = Gpio_speed_high;
Gpio_initstruct.alternate = Gpio_af0_spi2;
Hal_gpio_init (Gpiob, &gpio_initstruct);

Gpio_initstruct.pin = gpio_pin_14;
Gpio_initstruct.mode = gpio_mode_af_pp;
Gpio_initstruct.pull = Gpio_nopull;
Gpio_initstruct.alternate = Gpio_af0_spi2;
Hal_gpio_init (Gpiob, &gpio_initstruct);

Hal_gpio_writepin (Gpiob, Gpio_pin_12, Gpio_pin_set);
Gpio_initstruct.pin = Gpio_pin_12;
Gpio_initstruct.mode = gpio_mode_output_pp;
Hal_gpio_init (Gpiob, &gpio_initstruct);

The data cannot be read because the configuration mode is incorrect. All data outputs are configured to GPIO_MODE_AF_PP, this mode.

#define GPIO_MODE_AF_PP ((uint32_t) 0x00000002)/*!< Alternate Function Push Pull MODE */

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.