Download presentation
Presentation is loading. Please wait.
Published byTheresa Jones Modified over 7 years ago
1
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver
2
SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
What we need to know What tasks are needed for Lab. 3 and Lab. 4 (Fairly straightforward to answer – about 30 lines of code) What is “SPI hardware” and why to do you want to use it? What is the SPI “master slave” relationship? How do you send commands from the Blackfin to a SPI slave and control Logic Lab LED or Car control or LCD (Lab. 4)? 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
3
Final “temperature” program using co-operative scheduler
InitScheduler( ) with adjusted timer interrupt settings AddTask(InitHardware, NO_DELAY, RUN_ONCE) AddTask(MeasureTiming, NO_DELAY, 1); AddTask(CalculateTemperature, QUARTER_SECOND, QUARTER_SECOND) AddTask(DisplayTempertureLED, 3/8 seconds, QUARTER_SECOND) AddTask(FlashLED6, NO_DELAY, EIGHTH_SECOND StartScheduler( ) Loop GotoSleepTillInterrupt Dispatch Tasks Very easy to be able to add additional tasks and understand changes of system performance. All tasks written in “C and C++”
4
Lab 4 looks look The SPI_Message handling is all done during Lab. 3
InitScheduler( ) AddTask(InitHardware, NO_DELAY, RUN_ONCE) – including SPI and LCD AddTask(MeasureTiming, NO_DELAY, 1); AddTask(CalculateTemperature, QUARTER_SECOND, QUARTER_SECOND) AddTask(DisplayTempertureLED, 3/8 seconds, QUARTER_SECOND) AddTask(SPI_Message_HappyXmasLCD, ONE_SECOND, TWO_SECOND); AddTask(SPI_Message_TemperatureLCD, TWO_SECOND, TWO_SECOND); StartScheduler( ) Loop GotoSleepTillInterrupt Dispatch Tasks The SPI_Message handling is all done during Lab. 3
5
Lab 3 tests the SPI interface – must be much simpler
InitScheduler( ) with adjusted timer interrupt settings AddTask(InitHardware_SPI, NO_DELAY, RUN_ONCE) AddTask(SPI_Message_Simple1, 1/10 SECOND, 1 /5 SECOND); (or faster) AddTask(SPI_Message_Simple2, 1/4 SECOND, 1 /5 SECOND); StartScheduler( ) Loop GotoSleepTillInterrupt Dispatch Tasks The Messages are very simple – they simply flash the LED lights on the logic lab station is a “christmas tree light” fashion”
6
SPI_Message_Simple1( ) SPI_Message_Simple2( )
Both these tasks want to use SPI resource to send a message – conflict Fix by having each task “ask” the SPI_Controller if they can send a message – done by “semaphores” (also called “flags”) and “shared buffers” With a co-operative scheduler, the tasks execute one at a time and “only” one task can be changing these “shared flags and buffers” – No race conditions occur (two tasks trying to change the same variable) volatile int SPI_MessageCanBeSent_G = 0; volatile int pleaseSend_SPI_Message_G = 0; volatile short int SPI_Message_G[200]; volatile short int SPI_MessageSize_G = 0; 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
7
SPI_Message_Simple1( ) Racing LEDS 0 to 7 on Logic Lab.
void Task_SPI_Simple1(void) { static short int MyMessage[ ] = {0, 1, 3, 7, 15, 31, 63, 127}; // no lights, one light, two lights, three lights etc -- your choice // Ask SPI controller if anybody else using SPI interface if (SPI_MessageCanBeSent_G == 0) return; // Somebody else using SPI // This step only works with a “co-operative scheduler” where only 1 task can access memory SPI_MessageCanBeSent_G = 0; // Stop anybody else sending a message SPI_MessageSize_G = 8; for (int count = 0; count < SPI_MessageSize_G; count++) SPI_Message[count] = MyMessage[count]; // Copy message into shared buffer // Tell SPI controller that there is a message to send pleaseSendSPIMessage = 1; } 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
8
SPI Controller is another two task
Controller can’t send “all the message” along the SPI interface using wait loop LCD messages can take 400 ms or more Controller sends one character using a WriteOneSPIChar_Task( ) and goes back to sleep 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
9
void Task_SPI_controller(void)
volatile short int next_SPIinfo = 0; volatile short int nextValueReady = 0; // If 1, waiting for SPI to transmit void Task_SPI_Controller(void) { static counter = 0; // Count how many parts of message sent // No messages to send or last message already sent if (pleaseSendSPIMessage == 0) return; if (SPI_MessageSize_G == counter) { pleaseSendSPIMessage = 0; SPI_MessageCanBeSent_G = 1; counter = 0; return); if (nextValueReady != 0) return // SPI interface not ready – still transmitting last value next_SPIinfo = SPI_Message_G[counter++]; nextValueReady = 1; } 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
10
Lab 3 Now looks like this InitScheduler( ) AddTask(InitHardware_SPI, NO_DELAY, RUN_ONCE) AddTask(SPI_Controller, SHORT_DELAY, RUN_OFTEN) AddTask(SPI_Message_Simple1, 1/10 SECOND, 1 /5 SECOND); (or faster) AddTask(SPI_Message_Simple2, 1/4 SECOND, 1 /5 SECOND); AddTask(WriteSPIInfo, SHORT_DELAY, RUN_OFTEN); StartScheduler( ) And we have NO idea of how to write WriteSPIInfo( ) or InitHardware_SPI( ) as these interface to the SPI hardware directly. Need to learn about the SPI interface
11
SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
What is SPI Serial Peripheral Interface – an industry standard SPI is a serial communication bus developed by Motorola. It is a full-duplex protocol that functions on a master-slave paradigm that is ideally suited to data stream application. DUPLEX MEANS – BOTH DIRECTIONS AT ONCE Master can receive from the slave at the same time as the master sends to the slave Is essentially a 4 wire high speed system, with speeds up to many MHz Blackfin (p10-8) has a register SPI_BAUD where they talk about transfer rates of 25 MHz. Information is précised from SPI information -- LCD information -- 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
12
Advantages and drawbacks
SPI is a very simple communication protocol. It does not have a specific high-level protocol which means that there is almost no overhead. Data can be shifted at very high rates in full duplex mode This makes it very simple and efficient in a single master single slave scenario. The exchange itself has no pre-defined protocol. This makes it ideal for data-streaming applications. Data can be transferred at high speed, often into the range of the tens of megaHertz. The flipside is that there is no acknowledgment, no flow control, and the master may not even be aware of the slave's presence / or absence. You could do “some” handshaking via software 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
13
Concept of Master and Slave
The component that initiates the transfer The component that controls the transfer Slave The component that responds to the transfer 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
14
Master / Slave concept Slave Select (Chip Select)
Master sends out active low chip select signal SS1, then slave 1 responds Master sends out active low chip select signal SS2, then slave 2 responds FOR SAFETY – SELECT SIGNAL IS “ACTIVE LOW” NOT “ACTIVE HIGH” IF LINE BREAKS – FLOATS HIGH – TURNS SLAVE DEVICE OFF 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
15
Master / Slave concept Master to Slave data movement
Master sends out information to slave along MOSI wire Slave receives information from the master along MOSI wire Information (bits) is clocked by SCLK signal. 1-bit, 1 clock tick Learn the terms for Quiz 3 and Final MOSI --MASTER OUT – SLAVE IN 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
16
Master / Slave concept Slave to Master data movement
Master receives information from slave along MISO wire Slave sends information to the master along MISO wire Information (bits) is clocked by SCLK signal. 1-bit, 1 clock tick Don’t get master slave mixed up MISO --MASTER IN – SLAVE OUT 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
17
Lab. 3 interface SPI from Blackfin master (MOSI, MISO, CLK, PF5
SPI to interface (slave) (MOSI, MISO, CLK, slave select ) LINES TO LOGIC LAB LED OR CAR CONTROL TRANSMITTER OR LAB 4 LCD SCREEN 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
18
Transmit 16 bits with THIS format over the MOSI line
DB7, DB6, ………DB1, DB0 These signals come out on the CJ7 and CJ8 pins and go to the logic lab LEDs Leading “high-bit” MSB – Most significant bit comes out of Blackfin master first and is received by slave first Master and slave must agree (before hand – part of initial design) Does the MSB (bit 15) or LSB (bit 0) get transmitted first along the MOSI line 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
19
Lab. 3 ideas SPI_TDBR Blackfin Processor SPI_RXBR
SLAVE SELECT PF5 used (PF0 to PF7) SPI CLOCK MOSI MISO SLAVE OUTPUT INTERFACE SLAVE INPUT INTERFACE LOAD Slave to LCD DATA CONTROL SWITCHES (LOGIC LAB) CJ7 / CJ8 output lines to LOGIC LAB LEDs 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
20
SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
We know that any value written into SPI transmit data buffer register gets transmitted immediately extern volatile short int next_SPIinfo; extern volatile short int nextValueReady; void WriteSPIInfo (void) { if (nextValueReady == 0) return; Nothing to send *pSPI_TDBR = next_SPIinfo; WaitAwhileForSPIToTransmit( ) // how long is this ? // Is there a hardware flag we can read? nextValueReady = 0; // Tell SPI controller to send again? } 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
21
Questions still unanswered
How do we configure the SPI interface inside the Blackfin? How do we activate the chip-select line – PF5? Does activating the PF5 line as SPI output control mean we have to change all the SetupPF8to11ASM( ) and other routines? When do we activate the chip-select line, and how long for? What happens when there is not a new value in the SPI transmit buffer – what does the SPI interface do – it can’t do nothing – does it start transmitting zeros (which would turn out all the LEDs we just turned on 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
22
SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
What we need to know What tasks are needed for Lab. 3 and Lab. 4 (Fairly straightforward to answer – about 30 lines of code) What is “SPI hardware” and why to do you want to use it? What is the SPI “master slave” relationship? How do you send commands from the Blackfin to a SPI slave and control Logic Lab LED or Car control or LCD (Lab. 4)? 1/29/2018 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.