You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
913 B

  1. /*
  2. * gertboard.c:
  3. * Simple test for the SPI bus on the Gertboard
  4. *
  5. * Hardware setup:
  6. * D/A port 0 jumpered to A/D port 0.
  7. *
  8. * We output a sine wave on D/A port 0 and sample A/D port 0. We then
  9. * copy this value to D/A port 1 and use a 'scope on both D/A ports
  10. * to check all's well.
  11. *
  12. */
  13. #include <stdio.h>
  14. #include <stdint.h>
  15. //#include <stdlib.h>
  16. #include <math.h>
  17. #include <wiringPi.h>
  18. #include <gertboard.h>
  19. int main (void)
  20. {
  21. int angle ;
  22. int h1 ;
  23. uint32_t x1 ;
  24. printf ("Raspberry Pi Gertboard SPI test program\n") ;
  25. if (gertboardSPISetup () == -1)
  26. return 1 ;
  27. for (;;)
  28. {
  29. for (angle = 0 ; angle < 360 ; ++angle)
  30. {
  31. h1 = (int)rint (sin ((double)angle * M_PI / 180.0) * 127.0 + 128.0) ;
  32. gertboardAnalogWrite (0, h1) ;
  33. x1 = gertboardAnalogRead (0) ;
  34. gertboardAnalogWrite (1, x1 >> 2) ; // 10-bit A/D, 8-bit D/A
  35. }
  36. }
  37. return 0 ;
  38. }