Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver.

Similar presentations


Presentation on theme: "Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver."— Presentation transcript:

1 Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver

2 Lab 3 – Task 1 Check Equipment Split the programming or never get done
1 volatile unsigned char LED12345; 2 volatile unsigned short int switchValues( ) 3 Init_TTCOS511( ) 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_1, SEC / 30) – reads LED AddTask(DisplaySwitches, DELAY_2, ONE_SEC) – copies switchValues to LED AddTask(ReadSwitches, DELAY_3, ONE_SEC) – writes to switchValues Use Calgary Plus Parking Programming techniques NO WAITING UNLESS YOU PAY A PENALTY – (Lab does not work) QUESTION -- CHANGE DELAYS IN 5, 6, 7 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

3 Lab 3 Step 2 and 3 Volume Control SHARE THE CODING
1 volatile float volumeControl 2 Init_TTCOS511( ); // Activates a hidden Task that can “hold back” other tasks if too long 3 // AddPreExemptiveTask(ProcessAudioData, NO_DELAY, EVERY_TICK) // ProcessAudioData( ) – reads volumeControl 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_2, SEC / 30) – reads LED12345 6 AddTask(ReadSwitches, DELAY_1, SEC) – writes to switchValues 7 AddTask(DisplaySwitches, DELAY_3, ONE_SEC) – copies switchValues to LED12345 8 AddTask(VolumeControl_SW2, DELAY_4, SEC / 10) – reads switchValues, modifies volumeControl Question – adding Task 8 causes a design defect in which Task? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

4 Lab 3 Step 4 Flash LED6 Control SHARE THE CODING
1 volatile unsigned int LED6FlashRate 2 Init_TTCOS511( ); // Activates a hidden Task that can “hold back” other tasks if too long 3 // AddPreExemptiveTask(ProcessAudioData, NO_DELAY, EVERY_TICK) – reads volumeControl 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_2, SEC / 30) – reads LED12345 6 AddTask(ReadSwitches, DELAY_1, SEC) – writes to switchValues 7 AddTask(DisplaySwitches, DELAY_3, ONE_SEC) – copies switchValues to LED12345 8 AddTask(VolumeControl_SW2, DELAY_4, SEC / 10) – reads switchValues, modifies volumeControl – Kills current Task 6 and restarts it 9 AddTask(FlashRateLED6_SW3, DELAY_5, SEC / 10) – reads switchValues, modifies LED6FlashRate Question – adding Task 9 causes a design defect in which Task? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

5 Lab 3 Step 5 DisplayTemp( ) if SW1 is pressed SHARE THE CODING
1 volatile float currentTemperature; 2 Init_TTCOS511( ); // Activates a hidden Task that can “hold back” other tasks if too long 3 // AddPreEmpetiveTask(ProcessAudioData, NO_DELAY, EVERY_TICK) – reads volumeControl 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_2, SEC / 30) – reads LED12345 6 AddTask(ReadSwitches, DELAY_1, SEC) – writes to switchValues 7 AddTask(DisplaySwitches, DELAY_3, ONE_SEC) – copies switchValues to LED12345 8 AddTask(VolumeControl_SW2, DELAY_4, SEC / 10) – reads switchValues, modifies volumeControl – Kills current Task 6 and restarts it 9 AddTask(FlashRateLED6_SW3, DELAY_5, SEC / 10) – reads switchValues, modifies LED6FlashRate 10 AddTask(DisplayTemp_SW1, SEC / 4 + DELAY_6, SEC) – reads switchValues, currentTemperature, modifies LED12345 Question – introducing Task 10 causes a design defect in what task? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

6 Lab 3 Step 6 CalculateTemp( ) SHARE THE CODING
1 volatile float currentTemperature; volatile unsigned long T1_high, T2_low 2 Init_TTCOS511( ); // Activates a hidden Task that can “hold back” other tasks if too long 3 // AddPreEmpetiveTask(ProcessAudioData, NO_DELAY, EVERY_TICK) – reads volumeControl 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_2, SEC / 30) – reads LED12345 7 AddTask(DisplaySwitches, DELAY_3, ONE_SEC) – copies switchValues to LED12345 8 AddTask(VolumeControl_SW2, DELAY_4, SEC / 10) – reads switchValues, modifies volumeControl 9 AddTask(FlashRateLED6_SW3, DELAY_5, SEC / 10) – reads switchValues, modifies LED6FlashRate 10 AddTask(DisplayTemp_SW1, SEC / 4 + DELAY_6, SEC) – reads switchValues, currentTemperature, modifies LED12345 11 AddTask(CalculateTemp, SEC / 4 + DELAY_7, SEC) – reads T1 and T2, modifies currentTemperature Question – introducing Task 11 causes a design defect in what task? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

7 Lab 3 Step 7, 8, 9 Read thermal sensor on SW4 (PF11) SHARE THE CODING
1 volatile float currentTemperature; volatile unsigned long T1_high, T2_low 2 Init_TTCOS511( ); // Activates a hidden Task that can “hold back” other tasks if too long 3 // AddPreEmeptiveTask(ProcessAudioData, NO_DELAY, EVERY_TICK) – reads volumeControl 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_2, SEC / 30) – reads LED12345 7 AddTask(DisplaySwitches, DELAY_3, ONE_SEC) – copies switchValues to LED12345 8 AddTask(VolumeControl_SW2, DELAY_4, SEC / 10) – reads switchValues, modifies volumeControl 9 AddTask(FlashRateLED6_SW3, DELAY_5, SEC / 10) – reads switchValues, modifies LED6FlashRate 10 AddTask(DisplayTemp_SW1, SEC / 4 + DELAY_6, SEC) – reads switchValues, currentTemperature, modifies LED12345 11 AddTask(CalculateTemp, SEC / 4 + DELAY_7, SEC) – reads T1 and T2, modifies currentTemperature 12 AddTask(DetermineT1T2_SW4, SEC / 4 + DELAY_8, SEC / 10000) – reads SW4 (Thermal sensor signal), modifies T1 and T2 Question – introducing Task 12 causes a design defect in what task? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

8 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Lab 3 Step 10 Display Temperature Increasing / decreasing SHARE THE CODING 1 volatile float currentTemperature; volatile unsigned long T1_high, T2_low 2 Init_TTCOS511( ); // Activates a hidden Task that can “hold back” other tasks if too long 3 // AddPreEmeptiveTask(ProcessAudioData, NO_DELAY, EVERY_TICK) – reads volumeControl 4 AddTask(FlashLED6, NO_DELAY, ONE_SEC) 5 AddTask(DisplayLED12345, DELAY_2, SEC / 30) – reads LED12345 7 AddTask(DisplaySwitches, DELAY_3, ONE_SEC) – copies switchValues to LED12345 8 AddTask(VolumeControl_SW2, DELAY_4, SEC / 10) – reads switchValues, modifies volumeControl 9 AddTask(FlashRateLED6_SW3, DELAY_5, SEC / 10) – reads switchValues, modifies LED6FlashRate 10 AddTask(DisplayTemp_SW1, SEC / 4 + DELAY_6, SEC) – reads switchValues, currentTemperature, modifies LED12345 11 AddTask(CalculateTemp, SEC / 4 + DELAY_7, SEC) – reads T1 and T2, modifies currentTemperature 12 AddTask(DetermineT1T2_SW4, SEC / 6 + DELAY_8, SEC / 10000) – reads SW4 (Thermal sensor signal), modifies T1 and T2 13 AddTask(Race Lights_NOTSW1, SEC / 6 + DELAY_9, SEC / 10) Question – introducing Task 13 causes a design defect in what task? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

9 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Lab. 4 Use SPI interface, to cause the words “Happy 511 Christmas” to appear on the LCD screen some times and the temperature (Lab. 3) other times 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

10 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Lab. 4 Blackfin processor Running tasks using TTCOS operating system SPI-interface Optional car control 4 wires 11 wires SPI-bus External parallel I/O 4 wires SPI-interface 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

11 To cause the LCD to write the letter ‘A’ on its screen
LCD COMMANDS RS R/W DATA DB7 to DB0 WriteLetter(value) 1 value WriteLetter(‘a’) 0x61 That means we must send the following “voltage” signals to the LCD pins RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB Wait( 40 us) // EnableStrobe Wait( 40 us) 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

12 Lots of stuff has to happen in the correct order
Putting data into the Blackfin SPI_TDBR register causes the data to be transmitted over the MOSI line  However the external device will ACCEPT the command as the slave select line PF5 line is AUTOMATICALLY SET LOW by the Blackfin before the transmission is started.  When transmission is ended (16-bits sent) then the slave select line PF5 line is AUTOMATICALLY SET HIGH by the Blackfin  As PF5 line goes high the data sent by the Blackfin over the MOSI line to the special interface is transferred to the LCD  Everything in the garden is wonderful – most stuff happening automatically -- we just have to wire it correctly !!!!!!!!!!!!!! ALL? we have to do is make it happen!  2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

13 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Blackfin must be coded to transmit 16 bits with THIS format over the MOSI line DB7, DB6, ………DB1, DB0 E – Enable / Strobe 1  0 – When this line goes from high to the low, then the command is send to (latched into) LCD To make LCD respond to command 0x4F0 Then Blackfin must transmit 0x5F0 ( E High ) 0x4F0 ( E low ) 0x5F0 ( E high ) RS 1 – LCD data 0 – LCD instruction R/W 1 – Read from LCD 0 – Write to LCD 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

14 Lab 4 looks look – three new tasks
InitScheduler( ) AddTask(InitHardware, NO_DELAY, RUN_ONCE) AddTask(Init_SPIandLCD, NO_DELAY, RUN_ONCE) AddTask(MeasureTemperatureTiming, NO_DELAY, 1); AddTask(CalculateTemperature, QUARTER_SECOND, QUARTER_SECOND) AddTask(DisplayTempertureLED, 3/8 seconds, QUARTER_SECOND) AddTask(SPI_Message_HappyXmasLCD, 4.5_SECOND, TWO_SECOND); AddTask(SPI_Message_TemperatureLCD, 5.5_SECOND, TWO_SECOND); StartScheduler( ) Loop GotoSleepTillInterrupt Dispatch Tasks -- DO CODE REVIEW

15 Code reminder – using sprintf( ) Xmas message and temperature
I want to put the temperature (as a number) into a string that gets transmitted over SPI – how would I do that using “C”? volatile bool SPI_In_USE; // ‘SEMAPHORE’ (lock) volatile short int sendMyMessage; // ‘MESSAGE’ (simple) volatile char SPImessage[80]; // ‘MESSAGE’ body volatile float temperature; // Calculated as a Lab. 3 Task // Know terms in red for final #include <stdio.h> DO CODE REVIEW void SPI_Message_TemperatureLCD(void) { if (SPI_In_Use == true) return; // Must wait till SPI interface is not in use by another task // SPI_In_Use must be false – therefore we can change it and use SPI // We want to use the SPI interface – block other tasks from using it SPI_In_Use = true; sprintf(SPImessage, “Temperature %f4.2 C”, temperature); sendMyMessage = DATA; // DEFINE DATA AS 1 SOMEWHERE } 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

16 Difference between co-operative and pre-emptive schedulers
Race condition – SPI_In_Use flag might be changed by an interrupt from another device just as we try to change it void SPI_Message_TemperatureLCD(void) { if (SPI_In_Use == true) return; // Must wait till SPI interface is not in use by another task // SPI_In_Use must be false – therefore we can change it and use SPI // BUT Interrupt occurs “right at this moment” -- the interrupting device see SPI_In_USE is false so it changes it // and now the system has a “hardware defect present” – two things trying to use SPI // We want to use the SPI interface – block other tasks from using it NOT VALID NOW SPI_In_Use = true; sprintf(SPImessage, “Temperature %f4.2 C”, temperature); sendMyMessage = DATA; // DEFINE DATA AS 1 SOMEWHERE } // THIS SOLUTION IS NOT NEEDED IN CO-OPERATIVE SCHEDULER AS ONLY 1 TASK RUNS 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

17 Init LCD Screen ( ) – This is essentially “send a special message”
bool SPI_In_USE; // ‘SEMAPHORE’ (lock) short int sendMyMessage; // ‘MESSAGE’ (simple) char SPImessage[80]; // ‘MESSAGE’ body char LCDcommandString[ ] = {0x30, 0x30, 0x22, 0x00 /* end of string character */}; // LOOK AT LAB. 4 PRELAB REFERENCE SHEET #include <stdio.h> void InitLCDSreen (void) { if (SPI_In_Use == true) return; // Must wait till SPI interface is not in use by another task // SPI_In_Use is false // We want to use the SPI interface – block other tasks from using it SPI_In_Use = true; strcpy(SPImessage, LCDcommandString ); sendMyMessage = INSTRUCTION; // DEFINE INSTRUCTION AS 2 SOMEWHERE } -- DO CODE REVIEW 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

18 We now need to do the message handler task -- DO CODE REVIEW
enum {NO_MESSAGE, DATA, INSTRUCTION}; // Be able to explain “enum” for final void SPI_MessageHandler(void) { if ( sendMyMessage == NO_MESSAGE) return; // Message to send – start up the sending task numberCharactersToSend = strlen(SPIMessage); sendMessageTaskNumber = AddTask(SendMessageSPI_LCD, NO_DELAY, AS_FAST_AS_POSSIBLE); // Start with as FAST_AS_POSSIBLE with a slow value -- second / 20; } -- DO CODE REVIEW 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

19 To cause the LCD to write the letter ‘A’ on its screen
LCD COMMANDS RS R/W DATA DB7 to DB0 WriteLetter(value) 1 value WriteLetter(‘a’) 0x61 That means we must send the following “voltage” signals to the LCD pins RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB STATE 1 STATE 2 EnableStrobe STATE 3 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

20 SendMessageSPI_LCD( )
{ static int whichState = switch8HIGH; static int messageElement = 0; // Kill this task if all the elements in the message have been sent if (numberCharactersToSend == 0) { DeleteTask(sendMessageTaskNumber); SPIinUse = false; return; } -- DO CODE REVIEW 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

21 State 1 – send character + SW8 high + SW10 high IF data
#define SW8_high 0x DO CODE REVIEW #define SW8_low 0x DO CODE REVIEW #define SW10_High 0x DO CODE REVIEW #define SW10_Low 0x DO CODE REVIEW switch (whichState) { case STATE1: -- DO CODE REVIEW // get the character to send and convert to short int value (SPI using 16-bit values) unsigned short int SPIvalue = SPImessage(messageElement); // Next char to send // set switch 8 high SPIvalue = SPIvalue | SW8_high; -- DO CODE REVIEW // Do we set switch 10 high if (sendMyMessage == IS_INSTRUCTION) -- DO CODE REVIEW SPIvalue = SPIvalue | SW10_high; -- DO CODE REVIEW if (!SPIReady( ) ) return; // The SPI device might not be ready if Blackfin too fast WriteSPI(SPIvalue); nextState = STATE2 break; 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

22 You can finish off the other states present in SendMessageSPI_LCD( )
LCD COMMANDS RS SW10 R/W SW8 DATA DB7 to DB0 WriteLetter(value) 1 value WriteLetter(‘a’) 0x61 That means we must send the following “voltage” signals to the LCD pins RS R/W E DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB STATE 1 STATE 2 EnableStrobe STATE 3 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

23 All we have left to do is Init_SPIandLCD( ) Task
Use profound procrastination programming AddTask(InitSPI, NO_DELAY, RUN_ONCE); AddTask(SPI_MessageHandler, NO_DELAY, ½ SECOND); AddTask(InitLCDSreen, ONE_SECOND_DELAY, RUN+ONCE) -- DO CODE REVIEW 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

24 Things we are missing All relate to SPI HARDWARE
bool SPI_Ready(void) void WriteSPI(unsigned short SPIvalue); void InitSPI(void); We are going to have to read the reference sheet 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

25 Lab. 4 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 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

26 Chapter 10 in reference manual and reference sheet
SPI_Ready( ) code We don’t have a “ready to start ” bit – we have a “have finished” bit instead NOTE RO not R0 (Read only) SYSTEM CHANGED 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

27 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Concept We write 16-bits (0xFF0A) into SPI_TDBR Hardware transfers this to SHIFT register SPI_TDBR now empty For next 16 ticks of SPI clock Hardware sends out 1 bit from shift register over MOSI line to SLAVE each clock tick – speeds up to 25 MHz per bit (way faster than LEDs flashing speed) Hardware receives 1 bit over MISO line from the SLAVE and puts into shift register each clock tick – speeds up to 25 MHz per bit Hardware transfers shift register value (from slave) into SPI_RDBR (receive DBR) SPI_RDBR is now FULL This transmission over a serial line (16-bits 1 at a time) is much slower than other internal Blackfin operation Must be careful not to overwrite last transmission with new transmission by “trying to hard” – writing values too quickly 0x F F 0 A 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

28 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
TRY about 0x8000 to start with 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

29 SPI_registers -- Hardware Chap. 10 WHAT TO WORRY ABOUT WHAT TO IGNORE
SPI_BAUD – We want to be able to change this – slow it down to ??? Maximum serial clock rate is ¼ of the system clock rate SCK freq = Peripheral clock frequency / 2 * SPI_BAUD -- Many Mbits SPI_FLG (Not SPI_FLAG) – do we need ChangePFtoOutputASM FLS5 bit – activates PF5 as slave select line FLG5 bit – could be used by us to control value of PF5 line (Slave select) when FLG5 bit is low, PF5 output is low, when FLG5 bit is high, PF5 output is high, However we would rather have the SPI hardware change PF5 output line at the correct time for us. Page of the manual says “if CPHA = 0, the SPI hardware sets the output value (PF5) and the FLG5 bit (that developer sets) is ignored” MEANS WE WOULD NOT NEED TO CHANGE InitGPIOFlagsASM( ) SOUNDS GOOD TO ME – JUST “SET PLS5 TO 1” AND THE PROCESSOR DOES THE WORK -- except how do you make CPHA = 0? 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

30 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
SPI-registers -- more SPI_STAT – SPI Status register Has some read only bits RO bits are changed by processor hardware – not us Has some “write 1 to clear” sticky bits which are set when error condition occurs Remember to to write 1 to clear these bits during SPI Setup SPI_TDBR – transmit data buffer register Value written to this register is transmitted over SPI interface Writing to this register clears the SPI transmit interrupt signal One of the questions about writing the SPI_ISR function is answered by this information  When we write to the SPI_TDBR register, the interrupt signal is cleared automatically. We don’t have to clear a bit as we would do with the core timer and general purpose timer register interrupts However we not writing an SPI_ISR – what a shame – all that information going to waste 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

31 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
All set in InitSPI( ) Set this bit after others set Separate line of code ???? ???? DON’T SENT ZERO LCD “STROBE” IS 1 -> 0 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

32 SPI_CTL register InitSPI( ) Values needed during setup
TIMOD – transfer initiation mode 01 – Start transfer with write to SPI_TDBR. Interrupt when SPI_TDBR is empty. Timing issues possible here – get an interrupt after SPI_TDBR is empty the first time PSSE – Slave Select Enable 0 – Disable – setting this as 1 makes this Blackfin a slave device. There might be circumstances where you want one Blackfin as master, and another as a slave – but this is not one of them. SIZE = 1 (16 bits) LSBF – Last significant bit first 0 as we want MSBF first as that is the way the LCD interface has been designed MSTR – master 1 as we want Blackfin to be master, not slave SPE – SPI Enable 1 – but we might not want to do this during set-up, configure SPI up – then enable SPI as last step WOM – Write open drain master 0 – Normal – because this was the way the interface was designed EMISO – Enable MISO to allow slave to talk to master 0 – Not in this part of the lab GM – Get more data 0 – when SPI_RDBR (receive buffer) is full – discard new incoming data – don’t really care at the moment 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

33 Lab 4 quick test InitScheduler( )
AddTask(InitHardware, NO_DELAY, RUN_ONCE) AddTask(Init_SPIandLCD, NO_DELAY, RUN_ONCE) AddTask(AnythingOnMOSILine, 4.5_SECOND, TWO_SECOND); AddTask(MeasureTemperatureTiming, NO_DELAY, 1); AddTask(CalculateTemperature, QUARTER_SECOND, QUARTER_SECOND) AddTask(DisplayTempertureLED, 3/8 seconds, QUARTER_SECOND) AddTask(SPI_Message_HappyXmasLCD, 4.5_SECOND, TWO_SECOND); AddTask(SPI_Message_TemperatureLCD, 5.5_SECOND, TWO_SECOND); StartScheduler( ) Loop GotoSleepTillInterrupt Dispatch Tasks -- DO CODE REVIEW

34 AnythingOnMOSILine( ) – This is essentially “send a special message”
bool SPI_In_USE; // ‘SEMAPHORE’ (lock) short int sendMyMessage; // ‘MESSAGE’ (simple) char SPImessage[80]; // ‘MESSAGE’ body char SimpleTest[ ] = {0xFF, 0xAA, 0x23, 0x67, EOS /* end of string character */}; #include <stdio.h> void AnythingOnMOSILine (void) { if (SPI_In_Use == true) return; // Must wait till SPI interface is not in use by another task // SPI_In_Use is false // We want to use the SPI interface – block other tasks from using it SPI_In_Use = true; strcpy(SPImessage, SimpleTest); sendMyMessage = DATA; // DEFINE INSTRUCTION AS 2 SOMEWHERE } -- DO CODE REVIEW 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada

35 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada
Concept We write 16-bits (0xFF0A) into SPI_TDBR Hardware transfers this to SHIFT register SPI_TDBR now empty For next 16 ticks of SPI clock Hardware sends out 1 bit from shift register over MOSI line to SLAVE each clock tick – speeds up to 25 MHz per bit Hardware receives 1 bit over MISO line from the SLAVE and puts into shift register each clock tick – speeds up to 25 MHz per bit Hardware transfers shift register value (from slave) into SPI_RDBR (receive DBR) SPI_RDBR is now FULL This transmission over a serial line (16-bits 1 at a time) is much slower than other internal Blackfin operation Must be handled via interrupt control 0x F F 0 A 2/23/2019 SPI and LCD , Copyright M. Smith, ECE, University of Calgary, Canada


Download ppt "Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver."

Similar presentations


Ads by Google