Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
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.

63 lines
936 B

  1. /*
  2. * spi.cpp
  3. *
  4. * Created: 20/1/2016 10:10:39
  5. * Author: akatran
  6. */
  7. #include <avr/io.h>
  8. #include "gpio_helper.h"
  9. #include "spi.h"
  10. using namespace std;
  11. void SPI::begin(uint8_t _port)
  12. {
  13. if (_port==XMEGA_SPI_PORT_C) // Select SPI on PORTC
  14. {
  15. device = &SPIC;
  16. port = &PORTC;
  17. }else if (_port==XMEGA_SPI_PORT_D) // Select SPI on PORTD
  18. {
  19. device = &SPID;
  20. port = &PORTD;
  21. }
  22. init();
  23. }
  24. uint8_t SPI::transfer(uint8_t tx_)
  25. {
  26. register8_t data;
  27. device->DATA = tx_;
  28. while(!(device->STATUS & (1<<7)));
  29. data = device->DATA;
  30. //PORTF.OUT = data;
  31. return data;
  32. }
  33. void SPI::init()
  34. {
  35. port->DIRCLR = SPI_MISO_bm;
  36. port->DIRSET = SPI_MOSI_bm | SPI_SCK_bm | SPI_SS_bm;
  37. //device->CTRL = 0;
  38. device->CTRL = SPI_ENABLE_bm | SPI_MASTER_bm | SPI_MODE_0_gc | SPI_PRESCALER_DIV4_gc;
  39. device->INTCTRL =0; //Disable interrupts
  40. }
  41. SPI::SPI()
  42. {
  43. }
  44. SPI::~SPI()
  45. {
  46. }
  47. void operator delete(void * p) // or delete(void *, std::size_t)
  48. {
  49. }