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.
Revision 0:3b5e511afe7d, committed 2015-07-04
- Comitter:
- Piasiv1206
- Date:
- Sat Jul 04 05:56:33 2015 +0000
- Commit message:
- SPI Code
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 3b5e511afe7d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jul 04 05:56:33 2015 +0000 @@ -0,0 +1,122 @@ + + +// Payload uC (Tiva) -- > SPI master +// CDMS uC (Freescale) --> SPI slave +// packet length = 32*16 bits (32 bins --> each 2 bytes) + +#include "mbed.h" + +void FUNC_MASTER_WRITE(void); +const int addr = 0x20<<1; +const int addr1 = (0x20<<1|0); +Timer Siv ; +I2C master (D14,D15); +InterruptIn PYLD_I2C_Int(PTA13); +SPISlave device(PTD6, PTD7, PTD5,PTD4 ); // mosi, miso, sclk, ssel --> using SPI1 +InterruptIn PYLD_SPI_Interrupt(PTD2); +int payloadBins = 32; +float Stability_delay = 0.005228 ;// 0.005228 + +Serial pc(USBTX, USBRX); // tx, rx --> serial feedback for debug + +void payloadProcess() { + + + //wait(Stability_delay); // wait after interrupt for stability + unsigned short scienceRawPacket[payloadBins]; + + for(int i=0; i<payloadBins;i++){ + + + + while(!device.receive()); // blocking statement --> waiting for data from Payload + scienceRawPacket[i] = device.read(); // Read byte from master + + } + // serial feedback + pc.printf("Packet recieved\r\n"); + for(int i=0;i<payloadBins;i++){ + pc.printf("%d\t",scienceRawPacket[i]); + scienceRawPacket[i] = 0; + } + pc.printf("\r\n"); + +} +int dt3; +bool f = 1; +char rdata[10],rdata2; +void readds() +{ + + //wait(Stability_delay); + + f = master.read(addr,rdata,2); + // dt3 = master.read(1); + + +} + /* +int loop=1; +char *writedata = new char; +char data[100]= "kitten"; + +void FUNC_MASTER_WRITE(void) +{ int data1 = pc.getc(); + loop=1; + + + master.frequency(100000); + *writedata = data1; + while(loop) + { + // bool check = (bool)master.write(addr,data,8); + bool check = (bool)master.write(addr,data,13); + /* + master.start(); + bool check1 = master.write(addr1); + bool check2 = master.write(83); + master.write(97); + //wait(1); + master.write(107); + master.write(116); + master.write(104); + master.write(105); + master.write(32); + master.write(80); + master.write(114); + master.write(105); + master.write(121); + master.write(97); + + master.stop(); + + + + loop = 0; + } +} +*/ +int main() { + int dt1 = 0,dt2 = 0; + device.format(16,0); // SPI format --> 16 bits, mode = 0 + device.frequency(1000000); + // master.frequency(400000); + + pc.printf("Example code demonstarting Payload - CDMS SPI & I2C communication!\r\n"); + PYLD_SPI_Interrupt.rise(&payloadProcess); + // PYLD_I2C_Int.rise(&readds); + + while(1) + { + // FUNC_MASTER_WRITE(); + // wait(1); + // dt1 = rdata[0] ; + // dt2 = rdata[1] ; + //pc.printf("Temperature %d \n\r",rdata); + // pc.printf("Temperature %d \n\r",dt1); + // pc.printf("Temperature2 %d \n\r",dt2); + //pc.printf("Temperature3 %d \n\r",dt3); + + + } +}
diff -r 000000000000 -r 3b5e511afe7d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Jul 04 05:56:33 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file