Advertisement
Sumss

SPI

Nov 9th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial/all
  2.  
  3.  
  4. wiringPi I/O library for C/C++
  5. http://wiringpi.com/
  6.  
  7.  
  8.  
  9.  
  10.  
  11. //set up SPI
  12. clr r16
  13. ldi r16,(1<<SPE)|(0<<DORD)|(1<<MSTR) ;SPI Enable, MSB of the data word is transmitted first, Master
  14. out SPCR,r16 ;Save settings for SPI
  15. clr r16
  16. ldi r16,(1<<SPI2X) ;Set the speed setting
  17. out SPSR,r16 ;Save speed settings for SPI
  18.  
  19.  
  20.  
  21. ; --------------------------------------------------------------
  22. ; -- DRIVER - transmits data to the BCD-display
  23. ; -- Uses: r16,r17
  24. ; -- Gets data from stack (4 bytes)
  25. DRIV_TRANSMIT:
  26. //push all registers used.
  27. push r16
  28. push r17
  29. push ZH
  30. push ZL
  31.  
  32. //Load the Z pointer with stack pointer and add 7 to get down the the data.
  33. in ZH,SPH
  34. in ZL,SPL
  35. adiw Z,7
  36.  
  37. //Load the loop register to 4 (one for each of the data we need to send)
  38. ldi r16,4
  39. DISPLAY_TO_LED_TRANSMIT:
  40. ld r17,Z+ ;Get the data from the stack
  41. out SPDR, r17 ;Send the data
  42. DISPLAY_TO_LED_WAIT_TRANSMIT:
  43. sbis SPSR,SPIF ;Check if transmission is completed
  44. rjmp DISPLAY_TO_LED_WAIT_TRANSMIT ;If not, go back
  45. dec r16
  46. brne DISPLAY_TO_LED_TRANSMIT
  47.  
  48. //pop all registers used.
  49. pop ZL
  50. pop ZH
  51. pop r17
  52. pop r16
  53.  
  54. ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement