Siva ram
/
SPI_DAC_EPS_1
Nikunj and Harsha code
Fork of SPI_DAC_EPS by
main.cpp@0:b121e4eadb42, 2015-07-06 (annotated)
- Committer:
- Piasiv1206
- Date:
- Mon Jul 06 12:45:23 2015 +0000
- Revision:
- 0:b121e4eadb42
PYLD EPS working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Piasiv1206 | 0:b121e4eadb42 | 1 | #include "mbed.h" |
Piasiv1206 | 0:b121e4eadb42 | 2 | |
Piasiv1206 | 0:b121e4eadb42 | 3 | SPI spi(PTA16, PTA17, PTA15); // mosi, miso, sclk |
Piasiv1206 | 0:b121e4eadb42 | 4 | DigitalOut cs(PTD2); |
Piasiv1206 | 0:b121e4eadb42 | 5 | Serial pc(USBTX, USBRX); |
Piasiv1206 | 0:b121e4eadb42 | 6 | uint16_t input = 24576; |
Piasiv1206 | 0:b121e4eadb42 | 7 | uint16_t Num = 15 ; |
Piasiv1206 | 0:b121e4eadb42 | 8 | uint8_t K , F , i ,input2 = 0; |
Piasiv1206 | 0:b121e4eadb42 | 9 | |
Piasiv1206 | 0:b121e4eadb42 | 10 | int main() { |
Piasiv1206 | 0:b121e4eadb42 | 11 | // Chip must be deselected |
Piasiv1206 | 0:b121e4eadb42 | 12 | cs = 1; |
Piasiv1206 | 0:b121e4eadb42 | 13 | |
Piasiv1206 | 0:b121e4eadb42 | 14 | // Setup the spi for 8 bit data, high steady state clock, |
Piasiv1206 | 0:b121e4eadb42 | 15 | // second edge capture, with a 1MHz clock rate |
Piasiv1206 | 0:b121e4eadb42 | 16 | spi.format(8,0); // mode not decided |
Piasiv1206 | 0:b121e4eadb42 | 17 | spi.frequency(1000000); |
Piasiv1206 | 0:b121e4eadb42 | 18 | |
Piasiv1206 | 0:b121e4eadb42 | 19 | cs = 0; |
Piasiv1206 | 0:b121e4eadb42 | 20 | spi.write(input); |
Piasiv1206 | 0:b121e4eadb42 | 21 | spi.write(input2); |
Piasiv1206 | 0:b121e4eadb42 | 22 | cs = 1; |
Piasiv1206 | 0:b121e4eadb42 | 23 | |
Piasiv1206 | 0:b121e4eadb42 | 24 | |
Piasiv1206 | 0:b121e4eadb42 | 25 | |
Piasiv1206 | 0:b121e4eadb42 | 26 | for ( i = 0 ; i<= 15; i++ ) |
Piasiv1206 | 0:b121e4eadb42 | 27 | |
Piasiv1206 | 0:b121e4eadb42 | 28 | { |
Piasiv1206 | 0:b121e4eadb42 | 29 | |
Piasiv1206 | 0:b121e4eadb42 | 30 | cs = 0; // Select the device by seting chip select low |
Piasiv1206 | 0:b121e4eadb42 | 31 | |
Piasiv1206 | 0:b121e4eadb42 | 32 | spi.write(0x3F) ; // power up int ref and select all dacs 0b01101111 |
Piasiv1206 | 0:b121e4eadb42 | 33 | |
Piasiv1206 | 0:b121e4eadb42 | 34 | K = Num >> 8 ; |
Piasiv1206 | 0:b121e4eadb42 | 35 | spi.write ( K ); |
Piasiv1206 | 0:b121e4eadb42 | 36 | F = Num - ( K << 8 ) ; |
Piasiv1206 | 0:b121e4eadb42 | 37 | spi.write ( F) ; |
Piasiv1206 | 0:b121e4eadb42 | 38 | Num = Num + 2400 ; |
Piasiv1206 | 0:b121e4eadb42 | 39 | |
Piasiv1206 | 0:b121e4eadb42 | 40 | cs = 1; |
Piasiv1206 | 0:b121e4eadb42 | 41 | |
Piasiv1206 | 0:b121e4eadb42 | 42 | wait (1) ; |
Piasiv1206 | 0:b121e4eadb42 | 43 | pc.printf ("%d %d %d \n " , Num, F, K ); |
Piasiv1206 | 0:b121e4eadb42 | 44 | pc.printf( "\n\r"); |
Piasiv1206 | 0:b121e4eadb42 | 45 | |
Piasiv1206 | 0:b121e4eadb42 | 46 | } |
Piasiv1206 | 0:b121e4eadb42 | 47 | |
Piasiv1206 | 0:b121e4eadb42 | 48 | |
Piasiv1206 | 0:b121e4eadb42 | 49 | |
Piasiv1206 | 0:b121e4eadb42 | 50 | } |