Guest User

Untitled

a guest
Jan 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. ...
  2. enc28_write(MAADR5, mac_addr[0]);
  3. enc28_write(MAADR4, mac_addr[1]);
  4. enc28_write(MAADR3, mac_addr[2]);
  5. enc28_write(MAADR2, mac_addr[3]);
  6. enc28_write(MAADR1, mac_addr[4]);
  7. enc28_write(MAADR0, mac_addr[5]);
  8.  
  9. unsigned char enc28_readOp(unsigned char oper, unsigned char addr)
  10. {
  11. uint8_t dat = 0;
  12. GPIO_ResetBits(GPIOA, GPIO_Pin_4);
  13. Delay(2);
  14.  
  15. dat = (oper | (addr & ADDR_MASK));
  16. BSP_SPI1SendByte(dat);
  17. Delay(100);
  18. dat = BSP_SPI1SendByte(0xFF);
  19. Delay(200);
  20.  
  21. if (addr & 0x80)
  22. {
  23. dat = BSP_SPI1SendByte(0xFF);
  24. }
  25.  
  26. GPIO_SetBits(GPIOA, GPIO_Pin_4);
  27.  
  28. return dat;
  29. }
  30.  
  31. void enc28_writeOp(unsigned char op, unsigned char address, unsigned char data)
  32. {
  33. unsigned char dat = 0;
  34.  
  35. GPIO_ResetBits(GPIOA, GPIO_Pin_4);
  36.  
  37. dat = (op | (address & ADDR_MASK));
  38.  
  39. BSP_SPI1SendByte(dat);
  40.  
  41. dat = data;
  42.  
  43. BSP_SPI1SendByte(dat);
  44.  
  45. GPIO_SetBits(GPIOA, GPIO_Pin_4);
  46. }
  47.  
  48. uint8_t BSP_SPI1SendByte(uint8_t byte)
  49. {
  50. uint16_t timeout;
  51. //It is done in order to prevent the program hesitatng.
  52. timeout = TIMEOUT_TIME;
  53. while ((SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET) & (timeout != 0))
  54. {
  55. timeout--;
  56. }
  57.  
  58. SPI_I2S_SendData16(SPI1, byte);
  59.  
  60. timeout = TIMEOUT_TIME;
  61. while ((SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) & (timeout != 0))
  62. {
  63. timeout--;
  64. }
  65.  
  66. }
  67.  
  68. void SPI_I2S_SendData16(SPI_TypeDef *SPIx, uint16_t Data)
  69. {
  70. /* Check the parameters */
  71. assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
  72.  
  73. SPIx->DR = (uint16_t)Data;
  74. }
  75. uint16_t SPI_I2S_ReceiveData16(SPI_TypeDef *SPIx)
  76. {
  77. /* Check the parameters */
  78. assert_param(IS_SPI_ALL_PERIPH_EXT(SPIx));
  79.  
  80. return SPIx->DR;
  81. }
Add Comment
Please, Sign In to add comment