Advertisement
Guest User

DDD

a guest
Mar 29th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. MASTER
  2. ===========================================
  3. #define F_CPU 16000000UL
  4. #include "master.h"
  5.  
  6. #include <avr/io.h>
  7. #include <avr/pgmspace.h>
  8. #include <avr/interrupt.h>
  9. #include <stdio.h>
  10. #include <util/delay.h>
  11. #include "nRF905/nRF905.h"
  12.  
  13. #define RXADDR {0x58, 0x6F, 0x2E, 0x10} // Address of this device (4 bytes)
  14. #define TXADDR {0xFE, 0x4C, 0xA6, 0xE5} // Address of device to send to (4 bytes)
  15.  
  16. int main(void)
  17. {
  18. // LED indicator
  19. //config led
  20. DDRC |= _BV(DDC5);
  21.  
  22. // Start up
  23. nRF905_init();
  24.  
  25. // Set address of this device
  26. uint8_t addrRx[] = RXADDR;
  27. nRF905_setRXAddress(addrRx);
  28.  
  29. // Set address of device to send to
  30. uint8_t addr[] = TXADDR;
  31. nRF905_setTXAddress(addr);
  32.  
  33. // Interrupts on
  34. sei();
  35.  
  36. // Make buffer for data
  37. char mesaj[NRF905_MAX_PAYLOAD] = "test test";
  38.  
  39.  
  40. //on
  41. PORTC |= _BV(PORTC5);
  42.  
  43. while(1)
  44. {
  45. nRF905_setData(mesaj, sizeof(mesaj));
  46. while(!nRF905_send());
  47. }
  48. }
  49.  
  50. ==========================================================================
  51. SLAVE
  52. ==========================================================================
  53. #define F_CPU 16000000UL
  54. #include "slave.h"
  55.  
  56. #include <avr/io.h>
  57. #include <avr/pgmspace.h>
  58. #include <avr/interrupt.h>
  59. #include <stdio.h>
  60. #include <util/delay.h>
  61. #include "nRF905/nRF905.h"
  62. #include "UART.h"
  63.  
  64. #define RXADDR {0xFE, 0x4C, 0xA6, 0xE5} // Address of this device (4 bytes)
  65. #define TXADDR {0x58, 0x6F, 0x2E, 0x10} // Address of device to send to (4 bytes)
  66.  
  67. int main(void)
  68. {
  69. // LED indicator
  70. //config led
  71. DDRC |= _BV(DDC5);
  72.  
  73. UART_init();
  74. nRF905_init();
  75.  
  76. // Set address of this device
  77. uint8_t addrRx[] = RXADDR;
  78. nRF905_setRXAddress(addrRx);
  79.  
  80. // Interrupts on
  81. sei();
  82.  
  83. // Put into receive mode
  84. nRF905_receive();
  85.  
  86. uint8_t mesaj[NRF905_MAX_PAYLOAD];
  87.  
  88. UART_sendstring("start\r" , '\r');
  89.  
  90. //on
  91. PORTC |= _BV(PORTC5);
  92.  
  93. // Wait for data
  94. while(!nRF905_getData(mesaj, sizeof(mesaj)));
  95. UART_sendstring("ok\r" , '\r');
  96. //off
  97. PORTC &= ~_BV(PORTC5);
  98.  
  99. UART_sendstring(mesaj , '\r');
  100. }
  101.  
  102. ===================================================
  103. all UART stuff is a library that is fully working
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement