baseline build

Dependencies:   FastPWM mbed-os mbed

Committer:
jrhodes5150
Date:
Mon Jun 19 15:55:51 2017 +0000
Revision:
0:8a420ac6394e
initial build - baseline;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jrhodes5150 0:8a420ac6394e 1 #include "mbed.h"
jrhodes5150 0:8a420ac6394e 2 //#include "Thread.h"
jrhodes5150 0:8a420ac6394e 3 #include "SPIDAC.h"
jrhodes5150 0:8a420ac6394e 4
jrhodes5150 0:8a420ac6394e 5 DigitalOut spiChipSelect(p8, 1);
jrhodes5150 0:8a420ac6394e 6 spi_t spi;
jrhodes5150 0:8a420ac6394e 7
jrhodes5150 0:8a420ac6394e 8 void SPIDACInitialize(void)
jrhodes5150 0:8a420ac6394e 9 {
jrhodes5150 0:8a420ac6394e 10 // Setup the output pins for the SPI chip
jrhodes5150 0:8a420ac6394e 11 spi_init(&spi, p5, p6, p7, NC);
jrhodes5150 0:8a420ac6394e 12 // Set the format for the registers
jrhodes5150 0:8a420ac6394e 13 spi_format(&spi, 16, 2, 0);
jrhodes5150 0:8a420ac6394e 14 // Set the comm frequency
jrhodes5150 0:8a420ac6394e 15 spi_frequency(&spi, 1000000);
jrhodes5150 0:8a420ac6394e 16
jrhodes5150 0:8a420ac6394e 17 // Set the initial values
jrhodes5150 0:8a420ac6394e 18 SPIDACSend(0, 0);
jrhodes5150 0:8a420ac6394e 19 }
jrhodes5150 0:8a420ac6394e 20
jrhodes5150 0:8a420ac6394e 21 void SPIDACSend(uint16_t aValue, uint16_t bValue)
jrhodes5150 0:8a420ac6394e 22 {
jrhodes5150 0:8a420ac6394e 23 // First write the bValue to the B buffer
jrhodes5150 0:8a420ac6394e 24 spiChipSelect = 0;
jrhodes5150 0:8a420ac6394e 25 spi_master_write(&spi, ((bValue & 0xFFF) | (0x5000)));
jrhodes5150 0:8a420ac6394e 26 while( spi_busy(&spi) )
jrhodes5150 0:8a420ac6394e 27 continue;
jrhodes5150 0:8a420ac6394e 28 spiChipSelect = 1;
jrhodes5150 0:8a420ac6394e 29
jrhodes5150 0:8a420ac6394e 30 // Pause
jrhodes5150 0:8a420ac6394e 31 rtos::Thread::wait(1);
jrhodes5150 0:8a420ac6394e 32
jrhodes5150 0:8a420ac6394e 33 // Now write the aValue to A and move the B buffer to B register
jrhodes5150 0:8a420ac6394e 34 spiChipSelect = 0;
jrhodes5150 0:8a420ac6394e 35 spi_master_write( &spi, ((aValue & 0xFFF) | (0xC000)));
jrhodes5150 0:8a420ac6394e 36 while (spi_busy(&spi))
jrhodes5150 0:8a420ac6394e 37 continue;
jrhodes5150 0:8a420ac6394e 38 spiChipSelect = 1;
jrhodes5150 0:8a420ac6394e 39 }