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

Slides:



Advertisements
Similar presentations
Anurag Dwivedi Rudra Pratap Suman. Scope of Communica tion Telephones and Cell Phones.
Advertisements

Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Serial Interfaces, Part Deux -I 2 C and SPI December 4, 2002 Presented by Eugene Ho.
SPI Serial Peripheral Interface. SPI Serial Peripheral Interface is communication between two devices, one bit at a time sequential one bit at time over.
Lecture 8: Serial Interfaces
Peripherals and their Control An overview of industrially available “peripheral devices” Some ideas for Laboratories and Quiz / Exam questions.
Boot Issues Processor comparison TigerSHARC multi-processor system Blackfin single-core.
If we can just send 1 signal correctly over the MOSI line!!! Design and implementation details on the way to a valid SPI-LCD interface driver.
Thermal arm-wrestling Design of a video game using two programmable flags (PF) interrupts Tutorial on handling 2 Hardware interrupts from an external device.
Lab. 2 – More details – Tasks 4 to 6 1. What concepts are you expected to understand after the Lab. 2 is finished? 2. How do you demonstrate that you have.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Blackfin SPI Compatible Interface Design and implementation details on the way to a valid SPI-LCD interface driver.
HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver.
LCD programming Design and implementation details on the way to a valid SPI-LCD interface driver.
A look at interrupts What are interrupts and why are they needed in an embedded system? Equally as important – how are these ideas handled on the Blackfin.
Timers and Timing Signals Tutorial. 6/18/2015 Timer Control Copyright M. Smith, ECE, University of Calgary, Canada 2 / 31 Temperature Sensor -- Lab 3.
Serial Peripheral Interface (SPI)
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Getting the O in I/O to work on a typical microcontroller Ideas of how to send output signals to the radio controlled car. The theory behind the LED controller.
Getting the O in I/O to work on a typical microcontroller Activating a FLASH memory “output line” Part 1 Main part of Laboratory 1 Also needed for “voice.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 13.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
SPI Compatible Devices Design and implementation details on the way to a valid SPI-LCD interface driver.
Interfaces A practical approach. Lesson 2 I2C and SPI
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 10: Serial buses Oct 6, 2011.
Serial Peripheral Interface (SPI) Bus. SPI Bus There is no official specification for the SPI bus. It is necessary to consult the data sheets of the devices.
Serial Peripheral Interface Module MTT M SERIAL PERIPHERAL INTERFACE (SPI)
If we can just send 1 signal correctly over the MOSI line!!! Design and implementation details on the way to a valid SPI-LCD interface driver.
HD44780 LCD programming From the Hardware Side
4.0 rtos implementation part II
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
Volume. 1-the idea of the program is to increase, decrease the volume. 2-the program does the following: A-PF8:decrease the volume B-Pf9:increase the.
MICROPROCESSOR INPUT/OUTPUT
Lab. 2 Overview Move the tasks you developed in Lab. 1 into the more controllable TTCOS operating system Manual control of RC car.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Real-time Systems Lab, Computer Science and Engineering, ASU Quark SPI Interface (ESP – Fall 2014) Computer Science & Engineering Department Arizona State.
Lab. 2 Overview. Echo Switches to LED Lab1 Task 7 12/4/2015 TDD-Core Timer Library, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 28.
Multi-threaded projects Services and Drivers Alternate ways of doing Labs 1, 2, 3 and 4.
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
CSCI1600: Embedded and Real Time Software Lecture 16: Advanced Programming with I/O Steven Reiss, Fall 2015.
Department of Electronic & Electrical Engineering Serial interfaces Serial Interfaces allow communication between devices sending one bit at a time. In.
Serial Peripheral Interface SPI I2C (i-squared cee)
بسم الله الرحمن الرحيم MEMORY AND I/O.
1 Device Controller I/O units typically consist of A mechanical component: the device itself An electronic component: the device controller or adapter.
“Lab. 5” – Updating Lab. 3 to use DMA Test we understand DMA by using some simple memory to memory DMA Make life more interesting, since hardware is involved,
Developing Tasks to use with a co-operative scheduler Ideas for Assignment 2 Lab. 2, 3 and 4 Review for Midterm on Lab. 2 Ideas of defects, errors and.
1 Serial Peripheral Interface What is it? Basic SPI Capabilities Protocol Pros and Cons Uses Serial Peripheral Interface
©F.M. Rietti Communication Lines Fundamentals. ©F.M. Rietti LM-18 Computer Science SSI Embedded Systems I 2 Communication Lines Generally used to connect.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
EE 107 Fall 2017 Lecture 5 Serial Buses – UART & SPI
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
SPI Compatible Devices
CSCI1600: Embedded and Real Time Software
Lab. 2 Overview.
SPI Compatible Devices
Lab. 2 – More details – Later tasks
SPI Compatible Devices
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Thermal arm-wrestling
HD44780 LCD programming From the Hardware Side
HD44780 LCD programming From the Hardware Side
Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver.
Thermal arm-wrestling
Developing a reliable communication between Blackfin and Slave device
CSCI1600: Embedded and Real Time Software
Post Lab Quiz 3 Review Assignment 2 Help
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Chapter 13: I/O Systems.
Presentation transcript:

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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 26 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)?

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++”

Lab 4 looks look 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

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”

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; 5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 6 / 26

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; } 5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 7 / 26

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 5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 8 / 26

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; } 5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 9 / 26

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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 11 / 26 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 --

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 12 / 26 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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 13 / 26 Concept of Master and Slave Master The component that initiates the transfer The component that controls the transfer Slave The component that responds to the transfer

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 14 / 26 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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 15 / 26 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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 16 / 26 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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 17 / 26 Lab. 3 interface SPI from Blackfin master (MOSI, MISO, CLK, PF5 LINES TO LOGIC LAB LED OR CAR CONTROL TRANSMITTER OR LAB 4 LCD SCREEN SPI to interface (slave) (MOSI, MISO, CLK, slave select )

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 18 / 26 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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 19 / 26 Lab. 3 ideas SPI_TDBR Blackfin Processor SPI_RXBR CJ7 / CJ8 output lines to LOGIC LAB LEDs SWITCHES (LOGIC LAB) SLAVE INPUT INTERFACE SLAVE OUTPUT INTERFACE MOSIMISO SLAVE SELECT PF5 used (PF0 to PF7) DATA CONTROL SPI CLOCK LOAD Slave to LCD

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? } 5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 20 / 26

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 21 / 26 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

5/19/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 22 / 26 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)?