Permalink
Browse files

ein grosser schritt +1

  • Loading branch information...
1 parent a98b588 commit 9ad24cfef84c8a5f8b744c8ff356c421acd5baed @aeickho committed Sep 20, 2012
Showing with 421 additions and 364 deletions.
  1. +8 −0 uart_nrf_demo/crc.c
  2. +0 −9 uart_nrf_demo/main.c
  3. +17 −25 uart_nrf_demo/myspi.c
  4. +396 −330 uart_nrf_demo/nrf24l01p.c
View
@@ -1,20 +1,28 @@
#include <stdint.h>
+#include <p32xxxx.h>
+#include <plib.h>
+
#include "basic.h"
+#include "Pinguino.h"
// Calculate the CRC for transmitted and received data using
// the CCITT 16bit algorithm (X^16 + X^12 + X^5 + 1).
uint16_t crc16(uint8_t * buf, int len){
+
unsigned int crc=0xffff;
int i;
+
for(i=0;i<len;i++){
crc = (unsigned char)(crc >> 8) | (crc << 8);
crc ^= buf[i];
crc ^= (unsigned char)(crc & 0xff) >> 4;
crc ^= (crc << 8) << 4;
crc ^= ((crc & 0xff) << 4) << 1;
};
+
return crc;
+
};
/* Note:
View
@@ -264,23 +264,14 @@ main (void)
buf[2] = cnt >> 8;
buf[3] = cnt & 0xff;
-// mLED_2_On ();
ultoa (outBuf, cnt, 10);
UART2PutStr ("\n\r");
- UART2PutStr ("12345678901234567890");
- UART2PutStr ("\n\r");
-
UART2PutStr ("cnt: ");
UART2PutStr (outBuf);
UART2PutStr ("\n\r");
nrf_snd_pkt_crc (32, buf);
-// mLED_2_Off ();le
-
-
-// nrf_config_set (&oldconfig);
-// nrf_set_strength (3);
_delay_ms (10);
}
while (1);
View
@@ -5,6 +5,9 @@
#include "myspi.h"
#include "Pinguino.h"
+DmaChannel dmaTxChn = DMA_CHANNEL1; // DMA channel to use for our example
+
+
void
SPI2_init (void)
// Initialize pins for spi communication
@@ -33,6 +36,15 @@ SPI2_init (void)
SPI2STATCLR = 1 << 6; // clear SPIROV
SPI2CON = 0x8120;
+ DmaChnOpen (dmaTxChn, DMA_CHN_PRI2, DMA_OPEN_DEFAULT);
+ DmaChnSetEventControl (dmaTxChn,
+ DMA_EV_START_IRQ_EN |
+ DMA_EV_START_IRQ (_SPI2_TX_IRQ));
+ INTSetVectorPriority (INT_VECTOR_DMA (dmaTxChn), INT_PRIORITY_LEVEL_5);
+
+ INTSetVectorSubPriority (INT_VECTOR_DMA (dmaTxChn),
+ INT_SUB_PRIORITY_LEVEL_3);
+
;
}
@@ -85,7 +97,7 @@ SPI2_transfer_sync (uint8_t * dataout, uint8_t * datain, uint8_t len)
for (i = 0; i < len; i++)
{
-
+
out = dataout[i];
SPI2BUF = out;
// mLED_2_On ();
@@ -123,53 +135,33 @@ void
DmaTxIntFlag = 1;
DmaChnClrEvFlags (DMA_CHANNEL1, DMA_EV_BLOCK_DONE);
INTEnable (INT_SOURCE_DMA (DMA_CHANNEL1), INT_DISABLED); /// verschoben
- DmaChnDisable (DMA_CHANNEL1);
+// DmaChnDisable (DMA_CHANNEL1);
}
}
void
SPI2_transmit_sync (const uint8_t * dataout, uint8_t len)
{
- uint8_t i;
- char buf[10];
-
+ volatile uint8_t i;
if (len > 10)
{
- ultoa (buf, len, 10);
- DmaChannel dmaTxChn = DMA_CHANNEL1; // DMA channel to use for our example
- DmaChnOpen (dmaTxChn, DMA_CHN_PRI2, DMA_OPEN_DEFAULT);
- DmaChnSetEventControl (dmaTxChn,
- DMA_EV_START_IRQ_EN |
- DMA_EV_START_IRQ (_SPI2_TX_IRQ));
-
DmaChnSetTxfer (dmaTxChn, dataout, (void *) &SPI2BUF, len, 1, 1);
DmaChnSetEvEnableFlags (dmaTxChn, DMA_EV_BLOCK_DONE); // enable the transfer done interrupt, when all buffer transferred
-
- INTSetVectorPriority (INT_VECTOR_DMA (dmaTxChn), INT_PRIORITY_LEVEL_5);
-
- INTSetVectorSubPriority (INT_VECTOR_DMA (dmaTxChn),
- INT_SUB_PRIORITY_LEVEL_3);
-
DmaTxIntFlag = 0;
INTEnable (INT_SOURCE_DMA (dmaTxChn), INT_ENABLED);
- // INTEnableInterrupts ();
DmaChnStartTxfer (dmaTxChn, DMA_WAIT_NOT, 0);
while (!DmaTxIntFlag);
- volatile unsigned char discard=SPI2BUF;
- SPI2BRG = 4;
+ i = SPI2BUF; // sonst geht nichts ;-)
SPI2STATCLR = 1 << 6; // clear SPIROV
- SPI2CON = 0x8120;
-// SPI2CON = 0x8020;
-
-
}
else
{
+
for (i = 0; i < len; i++)
{
volatile char dummy;
Oops, something went wrong.

0 comments on commit 9ad24cf

Please sign in to comment.