Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SPI2_CS5532_Config(void){
- GPIO_InitTypeDef GPIO_InitStruct;
- SPI_InitTypeDef SPI_InitStrct;
- /* Chip Select CS5532*/
- /* Enable GPIOs clock */
- RCC_AHBPeriphClockCmd(CS5532_CS_GPIO_CLK, ENABLE);
- /* Configure CS in Output Push-Pull mode */
- GPIO_InitStruct.GPIO_Pin = CS5532_CS_PIN;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_40MHz;
- GPIO_Init(CS5532_CS_GPIO_PORT, &GPIO_InitStruct);
- /* Set chip select pin high */
- CS5532_CS_HIGH;
- /* Configure SPI for CS5532 */
- /* Enable GPIOs clock */
- RCC_AHBPeriphClockCmd(SPI_MOSI_GPIO_CLK | SPI_MISO_GPIO_CLK | SPI_SCK_GPIO_CLK, ENABLE);
- /* Enable SPI clock */
- RCC_APB1PeriphClockCmd(CS5532_SPI_CLK, ENABLE);
- /* Configure SPI SCK pin */
- GPIO_InitStruct.GPIO_Pin = SPI_SCK_PIN;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(SPI_SCK_GPIO_PORT, &GPIO_InitStruct);
- /* Configure SPI MISO pin */
- GPIO_InitStruct.GPIO_Pin = SPI_MISO_PIN;
- GPIO_Init(SPI_MISO_GPIO_PORT, &GPIO_InitStruct);
- /* Configure SPI MOSI pin */
- GPIO_InitStruct.GPIO_Pin = SPI_MOSI_PIN;
- GPIO_Init(SPI_MOSI_GPIO_PORT, &GPIO_InitStruct);
- /* Connect SCK, MISO and MOSI pins to SPI alternate */
- GPIO_PinAFConfig(SPI_SCK_GPIO_PORT, SPI_SCK_SOURCE, SPI_SCK_AF);
- GPIO_PinAFConfig(SPI_MISO_GPIO_PORT, SPI_MISO_SOURCE, SPI_MISO_AF);
- GPIO_PinAFConfig(SPI_MOSI_GPIO_PORT, SPI_MOSI_SOURCE, SPI_MOSI_AF);
- /* Configure SPI for CS5532*/
- SPI_InitStrct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // transmisja z wykorzystaniem jednej linii, transmisja jednokierunkowa
- SPI_InitStrct.SPI_Mode = SPI_Mode_Master; // Tryb Pracy SPI
- SPI_InitStrct.SPI_DataSize = SPI_DataSize_8b; // 8-bitowa ramka danych
- SPI_InitStrct.SPI_CPOL = SPI_CPOL_Low; // stan sygnalu taktujacego przy braku transmisji - niski
- SPI_InitStrct.SPI_CPHA = SPI_CPHA_1Edge; // aktywne zbocze sygnalu taktujacego - 1-sze zbocze
- SPI_InitStrct.SPI_NSS = SPI_NSS_Soft; // softwerowa obsluga linii NSS (CS)
- SPI_InitStrct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; // 32MHz/16 = 2MHz
- SPI_InitStrct.SPI_FirstBit = SPI_FirstBit_MSB; // pierwszy bit w danych najmniej znaczacy
- SPI_Init(SPI2, &SPI_InitStrct); // inicjalizacja SPI
- // Wlacz SPI2
- SPI_Cmd(SPI2, ENABLE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement