Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- enc28_write(MAADR5, mac_addr[0]);
- enc28_write(MAADR4, mac_addr[1]);
- enc28_write(MAADR3, mac_addr[2]);
- enc28_write(MAADR2, mac_addr[3]);
- enc28_write(MAADR1, mac_addr[4]);
- enc28_write(MAADR0, mac_addr[5]);
- unsigned char enc28_readOp(unsigned char oper, unsigned char addr)
- {
- uint8_t dat = 0;
- GPIO_ResetBits(GPIOA, GPIO_Pin_4);
- Delay(2);
- dat = (oper | (addr & ADDR_MASK));
- BSP_SPI1SendByte(dat);
- Delay(100);
- dat = BSP_SPI1SendByte(0xFF);
- Delay(200);
- if (addr & 0x80)
- {
- dat = BSP_SPI1SendByte(0xFF);
- }
- GPIO_SetBits(GPIOA, GPIO_Pin_4);
- return dat;
- }
- void enc28_writeOp(unsigned char op, unsigned char address, unsigned char data)
- {
- unsigned char dat = 0;
- GPIO_ResetBits(GPIOA, GPIO_Pin_4);
- dat = (op | (address & ADDR_MASK));
- BSP_SPI1SendByte(dat);
- dat = data;
- BSP_SPI1SendByte(dat);
- GPIO_SetBits(GPIOA, GPIO_Pin_4);
- }
- uint8_t BSP_SPI1SendByte(uint8_t byte)
- {
- uint16_t timeout;
- //It is done in order to prevent the program hesitatng.
- timeout = TIMEOUT_TIME;
- while ((SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) & (timeout != 0))
- {
- timeout--;
- }
- SPI_I2S_SendData16(SPI1, byte);
- timeout = TIMEOUT_TIME;
- while ((SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) & (timeout != 0))
- {
- timeout--;
- }
- }
- void SPI_I2S_SendData16(SPI_TypeDef *SPIx, uint16_t Data)
- {
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- SPIx->DR = (uint16_t)Data;
- }
- uint16_t SPI_I2S_ReceiveData16(SPI_TypeDef *SPIx)
- {
- /* Check the parameters */
- assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
- return SPIx->DR;
- }
Add Comment
Please, Sign In to add comment