Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:eb558d650b17
- Parent:
- 1:25c850668cef
- Child:
- 3:c2b09e28978a
diff -r 25c850668cef -r eb558d650b17 main.cpp
--- a/main.cpp Fri Mar 20 20:56:43 2015 +0000
+++ b/main.cpp Tue Mar 24 22:11:00 2015 +0000
@@ -86,7 +86,7 @@
#define REG_FREQ1 0x8000
#define REG_FREQ0 0x4000
void setFrequencyWord(bool reg, uint32_t frequency) {
- writeReg(0x2000);
+ writeReg(0x2000); // sets the PIN/SW D9 pin to high >> FSELECT pin can be used to use either FREQ0 or FREQ1
writeReg((reg?REG_FREQ1:REG_FREQ0) | (frequency & 0x3FFF));
writeReg((reg?REG_FREQ1:REG_FREQ0) | ((frequency >> 14) & 0x3FFF));
}
@@ -138,6 +138,22 @@
reset(false);
}
+uint8_t Crc8(uint8_t *vptr, int len)
+{
+ uint8_t *data = vptr;
+ unsigned crc = 0;
+ int i, j;
+ for (j = len; j; j--, data++) {
+ crc ^= (*data << 8);
+ for(i = 8; i; i--) {
+ if (crc & 0x8000)
+ crc ^= (0x1070 << 3);
+ crc <<= 1;
+ }
+ }
+ return (uint8_t)(crc >> 8);
+}
+
/*******************
MAIN
*******************/
@@ -165,10 +181,56 @@
//output calculation
//fOut = fMCLK / 2^28 * FREQREG = 16e6 / 2^28 * FREQREG
//FREQREG = fOut * 2^28 / 16e6 = fOut * 16.777216
- setFrequencyWord(0, 16777216);
- selectFrequency(0);
+ setFrequencyWord(0, 16777216); //1MHz: bin 0
+ setFrequencyWord(1, 33554432); //2MHz: bin 1
setSignOutput(SIGN_OUTPUT_MSB);
//open the DDS output
SQUARE = 1;
+
+ #define bit_up_time 8 //8 for no logic
+ #define bit_guard_time 8 //8 for no logic
+ #define data_reset_time 16 //16 for no logic
+
+ //specify the data
+ #define data_len 9 //in bytes, remember to leave the last byte as 0 for the crc
+ uint8_t data[data_len] = {0xAA, 0xFF, 0xD0, 0x59, 0xE4, 0xCC, 0x1A, 0x2A, 0}; //bt mac format: header, type, data ... data, crc (crc should be 0x89 in this case)
+ data[data_len-1] = Crc8(&data[1], data_len-2); //crc includes everything except the header byte
+ uint8_t bytecount = 0, bitcount = 0;
+ int32_t freq = 0;
+ uint8_t freqRegister = 0;
+
+ __disable_irq();
+ while(1) {
+ for (bytecount=0; bytecount<data_len; bytecount++){
+ for(bitcount=0; bitcount<8; bitcount++){
+ if ( (( data[bytecount]>>bitcount ) & 0x01) == 0){ //send binary 0
+
+ selectFrequency(0);
+ SQUARE = 1;
+
+ wait_ms(bit_up_time);
+
+ SQUARE = 0;
+ //set_DDS(DDS_MCLK_SLEEP); //THIS CAUSES PROBLEMS - ENVELOPE ON DATA?
+ wait_ms(bit_guard_time);
+
+ } else { //send binary 1
+ selectFrequency(1);
+ SQUARE = 1;
+
+ wait_ms(bit_up_time);
+
+ SQUARE = 0;
+ //set_DDS(DDS_MCLK_SLEEP); //THIS CAUSES PROBLEMS - ENVELOPE ON DATA?
+ wait_ms(bit_guard_time);
+ }
+ }//end bitcount
+ }//end bytecount
+
+ wait_ms(data_reset_time); //all the data has been sent, delay for some time to reset
+
+ }//end while
+ __enable_irq();
+
}