void _enc28j60_resetDeassert(ENC28J60 *enc28j60) { GPIO_setBits(enc28j60->resetPort, enc28j60->resetPin); }
void init_SPI2(void) { GPIO_InitTypeDef GPIO_InitStruct; SPI_InitTypeDef SPI_InitStruct; // enable clock for used IO pins RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Configure pins used by SPI2 * PB10 = SCK * PC2 = MISO * PC3 = MOSI * PB14 = NSS * */ // PORT B SCK GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOB, &GPIO_InitStruct); // PORT C MISO and MOSI GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN; GPIO_Init(GPIOC, &GPIO_InitStruct); // PORT B NSS GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStruct); // connect SPI1 pins to SPI alternate function GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOC, GPIO_PinSource2, GPIO_AF_SPI2); GPIO_PinAFConfig(GPIOC, GPIO_PinSource3, GPIO_AF_SPI2); GPIO_setBits(GPIOB, GPIO_Pin_14); // set PB14 high // enable peripheral clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); /* configure SPI1 in Mode 0 * CPOL = 1 --> clock is high when idle * CPHA = 0 --> data is sampled at the first edge */ //SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex; // set to full duplex mode, seperate MOSI and MISO lines SPI_InitStruct.SPI_Direction = SPI_Direction_1Line_Rx; SPI_InitStruct.SPI_Mode = SPI_Mode_Master; // transmit in master mode, NSS pin has to be always high SPI_InitStruct.SPI_DataSize = SPI_DataSize_16b; // one packet of data is 16 bits wide SPI_InitStruct.SPI_CPOL = SPI_CPOL_High; // clock is high when idle SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge; // data sampled at first edge //SPI_InitStruct.SPI_NSS = SPI_NSS_Soft | SPI_NSSInternalSoft_Set; // set the NSS management to internal and pull internal NSS high SPI_InitStruct.SPI_NSS = SPI_NSS_Hard; SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; // SPI frequency is APB1 frequency / 256 SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;// data is transmitted MSB first SPI_Init(SPI2, &SPI_InitStruct); SPI_SSOutputCmd(SPI2, ENABLE); SPI_Cmd(SPI2, ENABLE); // enable SPI2 }
void _enc28j60_csDeassert(ENC28J60 *enc28j60) { GPIO_setBits(enc28j60->csPort, enc28j60->csPin); }