Advertisement
jh_elec

Software SPI Write

Mar 16th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. void spiSoftWrite( uint8_t byte )
  2. {
  3.     uint8_t n = 0;
  4.    
  5.     for (n = 0 ; n < 8 ; n++)
  6.     {
  7.         PORT(SPI_SOFT_SCK_DDR) &= ~(1<<SPI_SOFT_SCK_BP);    // SCK = 0
  8.        
  9.         if (byte & 0x80)
  10.         {
  11.             PORT(SPI_SOFT_SDA_DDR) |=  (1<<SPI_SOFT_SDA_BP);    // SD = 1
  12.         }
  13.         else
  14.         {
  15.             PORT(SPI_SOFT_SDA_DDR) &= ~(1<<SPI_SOFT_SDA_BP);    // SD = 0
  16.         }
  17.         byte <<= 1;
  18.  
  19.         PORT(SPI_SOFT_SCK_DDR) |= (1<<SPI_SOFT_SCK_BP); // SCK = 1
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement