Last active
August 29, 2015 14:15
-
-
Save tonyarkles/0438f4f00a5cf41044ce to your computer and use it in GitHub Desktop.
radio init
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void radio_init(void) { | |
/* Pin connections | |
* o PB5 radio reset | |
* o PB4 /cscon | |
* o PB3 /csdata | |
* PA7 mosi | |
* PA6 miso | |
* PA5 sck | |
* i PB15 plready | |
* i PB14 txdone | |
*/ | |
/* Turn on the clocks */ | |
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); | |
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); | |
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); | |
GPIO_InitTypeDef gp; | |
/* Output pins */ | |
gp.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_5 | GPIO_Pin_4 | GPIO_Pin_3; | |
gp.GPIO_Mode = GPIO_Mode_OUT; | |
gp.GPIO_Speed = GPIO_Speed_50MHz; | |
gp.GPIO_OType = GPIO_OType_PP; | |
gp.GPIO_PuPd = GPIO_PuPd_NOPULL; | |
GPIO_Init(GPIOB, &gp); | |
/* Input pins */ | |
gp.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14; | |
gp.GPIO_Mode = GPIO_Mode_IN; | |
gp.GPIO_PuPd = GPIO_PuPd_DOWN; | |
GPIO_Init(GPIOB, &gp); | |
/* SPI */ | |
GPIO_PinAFConfig(GPIOA, GPIO_Pin_5, GPIO_AF_0); | |
GPIO_PinAFConfig(GPIOA, GPIO_Pin_6, GPIO_AF_0); | |
GPIO_PinAFConfig(GPIOA, GPIO_Pin_7, GPIO_AF_0); | |
gp.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7; | |
gp.GPIO_Mode = GPIO_Mode_AF; | |
GPIO_Init(GPIOA, &gp); | |
SPI_InitTypeDef spi; | |
spi.SPI_Direction = SPI_Direction_2Lines_FullDuplex; | |
spi.SPI_Mode = SPI_Mode_Master; | |
spi.SPI_DataSize = SPI_DataSize_8b; | |
spi.SPI_CPOL = SPI_CPOL_Low; | |
spi.SPI_CPHA = SPI_CPHA_1Edge; | |
spi.SPI_NSS = SPI_NSS_Soft; | |
spi.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; | |
spi.SPI_FirstBit = SPI_FirstBit_MSB; | |
spi.SPI_CRCPolynomial = 0; | |
SPI_Init(SPI1, &spi); | |
SPI_Cmd(SPI1, ENABLE); | |
radio_reset(); | |
/* Default /CSDAT and /CSCON high */ | |
GPIO_WriteBit(GPIOB, GPIO_Pin_4, 1); | |
GPIO_WriteBit(GPIOB, GPIO_Pin_3, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment