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.
Fork of Muscle_Controlled_Servo by
Diff: SPI.cpp
- Revision:
- 3:d6e142b6ead1
- Parent:
- 2:b615682e3e4f
- Child:
- 4:bcef9164776e
--- a/SPI.cpp Sun Apr 01 15:54:46 2018 +0000
+++ b/SPI.cpp Sun Apr 01 16:22:36 2018 +0000
@@ -4,9 +4,12 @@
// However using multi SPI devices within FPGA with a seperate chip select
SPI spi_cmd(PA_7, PA_6, PA_5); // NB another instance call spi_cmd for 8 bit SPI dataframe see later line 37
// For each device NB PA_7 PA_6 PA_5 are D11 D12 D13 respectively
-DigitalOut cs(PC_6); // Chip Select for Basic Outputs to illuminate Onboard FPGA DEO nano LEDs CN7 pin 1
-DigitalOut LCD_cs(PB_15); // Chip Select for the LCD via FPGA CN7 pin 3
-DigitalOut ADC_cs(PB_9); // Chip Select for the ADC via FPGA CN7 pin 4
+
+//DigitalOut LED_cs(PC_6); // Chip Select for Basic Outputs to illuminate Onboard FPGA DEO nano LEDs CN7 pin 1
+//DigitalOut LCD_cs(PB_15); // Chip Select for the LCD via FPGA CN7 pin 3
+//DigitalOut ADC_cs(PB_9); // Chip Select for the ADC via FPGA CN7 pin 4
+
+BusOut cs(PB_9,PB_15,PC_6); // Chip Select => 111(7) = Nothing, 110(6) = General, 101(5) = LCD, 011(3) = ADC
//NBB the following line for F429ZI !!!!
DigitalIn DO_NOT_USE(PB_12); // MAKE PB_12 (D19) an INPUT do NOT make an OUTPUT under any circumstances !!!!! ************* !!!!!!!!!!!
@@ -20,9 +23,10 @@
//Ticker ticktock;
void SPI_INIT (void)
{
- cs = 1; // Chip must be deselected, Chip Select is active LOW
+ LED_cs = 1; // Chip must be deselected, Chip Select is active LOW
LCD_cs = 1; // Chip must be deselected, Chip Select is active LOW
ADC_cs = 1; // Chip must be deselected, Chip Select is active LOW
+
spi.format(16,0); // Setup the DATA frame SPI for 16 bit wide word, Clock Polarity 0 and Clock Phase 0 (0)
spi_cmd.format(8,0); // Setup the COMMAND SPI as 8 Bit wide word, Clock Polarity 0 and Clock Phase 0 (0)
spi.frequency(1000000); // 1MHz clock rate
@@ -68,18 +72,18 @@
//LED Chaser display KIT lives on!
for (uint32_t i=1;i<=128;i*=2)
{
- cs = 0; //Select the device by seting chip select LOW
+ LED_cs = 0; //Select the device by seting chip select LOW
spi_cmd.write(0);
spi.write(i);
- cs = 1; //De-Select the device by seting chip select HIGH
+ LED_cs = 1; //De-Select the device by seting chip select HIGH
wait_ms(20);
}
for (uint32_t i=128;i>=1;i/=2)
{
- cs = 0; //Select the device by seting chip select LOW
+ LED_cs = 0; //Select the device by seting chip select LOW
spi_cmd.write(0);
spi.write(i);
- cs = 1; //De-Select the device by seting chip select HIGH
+ LED_cs = 1; //De-Select the device by seting chip select HIGH
wait_ms(20);
}
}
@@ -173,10 +177,10 @@
int read_switches(void){
int sw_val;
- cs = 0;
+ LED_cs = 0;
spi_cmd.write(0);
sw_val = spi.write(0x00)&0x0F; // Just want lower 4bit nibble
- cs = 1 ;
+ LED_cs = 1 ;
if (sw_val&(1<<0)){printf("Switch 0 :");}
if (sw_val&(1<<1)){printf("Switch 1 :");}
if (sw_val&(1<<2)){printf("Switch 2 :");}
