Now we must send the correct signals over the MOSI line!!! Design and implementation details on the way to a valid SPI-LCD interface driver.

Slides:



Advertisements
Similar presentations
Lab. 2 Overview. Lab. 2 and Assignment 3 Many Lab. 2 and Assignment 3 tasks involve “downloading” provided code, compiling and linking into a project.
Advertisements

A look at interrupts What are interrupts and why are they needed.
Microprocessor or Microcontroller Not just a case of “you say tomarto and I say tomayto” M. Smith, ECE University of Calgary, Canada.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Boot Issues Processor comparison TigerSHARC multi-processor system Blackfin single-core.
Daddy! -- Where do instructions come from? Program Sequencer controls program flow and provides the next instruction to be executed Straight line code,
6/2/2015 Labs in ENCM415. Laboratory 2 PF control, Copyright M. Smith, ECE, University of Calgary, Canada 1 Temperature Sensor Laboratory 2 Part 2 – Developing.
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.
Building a simple loop using Blackfin assembly code M. Smith, Electrical and Computer Engineering, University of Calgary, Canada.
Specialized Video (8-bit) and Vector (16-bit) Instructions on the Blackfin There is always a “MAKE-UP-YOUR-QUESTION-AND-ANSWER-IT” Question on a Dr. Smith.
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.
Core Timer Code Development How you could have done the Take- Home Quiz using a test driven development (TDD) approach.
HD44780 LCD programming From the Hardware Side Design and implementation details on the way to a valid SPI-LCD interface driver.
Specialized Video (8-bit) and Vector (16-bit) Instructions on the Blackfin Expand on these ideas for Q9 question and answer on the final.
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.
Lab. 2 Overview 1. What concepts are you expected to understand after the Lab. 2 is finished? 2. How do you demonstrate that you have that knowledge?
Understanding the Blackfin ADSP-BF5XX Assembly Code Format
Serial Peripheral Interface (SPI)
A look at interrupts What are interrupts and why are they needed.
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.
Laboratory 1 – ENCM415 Familiarization with the Analog Devices’ VisualDSP++ Integrated Development Environment.
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.
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.
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
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Over-view of Lab. 1 See the Lab. 1 web-site and the lecture notes for more details.
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.
Building a simple loop using Blackfin assembly code If you can handle the while-loop correctly in assembly code on any processor, then most of the other.
“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,
Over-view of Lab. 1 See the Lab. 1 web-site and latter lecture notes for more details.
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.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
SPI Compatible Devices
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
SPI Compatible Devices
Thermal arm-wrestling
DMA example Video image manipulation
The planned and expected
Lab. 2 – More details – Later tasks
SPI Compatible Devices
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
Thermal arm-wrestling
Using Arrays Completion of ideas needed for a general and complete program Final concepts needed for Final.
Moving Arrays -- 2 Completion of ideas needed for a general and complete program Final concepts needed for Final DMA.
HD44780 LCD programming From the Hardware Side
HD44780 LCD programming From the Hardware Side
Expand on these ideas for Q9 question and answer on the final
General purpose timers
Thermal arm-wrestling
Concept of TDD Test Driven Development
Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver.
Lab. 4 – Part 2 Demonstrating and understanding multi-processor boot
Independent timers build into the processor
Thermal arm-wrestling
Building a simple loop using Blackfin assembly code
Developing a reliable communication between Blackfin and Slave device
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.
Presentation transcript:

Now we must send the correct signals over the MOSI line!!! Design and implementation details on the way to a valid SPI-LCD interface driver

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 24 To be tackled today All the new SPI stuff about “trying to get the code to work” We want the code “to work in someway – even if very slowly” Later we could “refactor the code for speed” Meaning if I can find the time to get the DMA to work (and it is easy to do) we will get that bit going in Lab. 4 as a bonus (or is very easy as part of Lab. 4 Look at first 3 tasks of Lab. 4

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 3 / 24 Review -- Master / Slave concept Slave Select (Chip Select) We put a value into the Blackfin SPI_TDBR register Blackfin sends out active low chip select signal PF5 Blackfin sends out the “value- bits” on the MOSI signal. Slave accepts signal as SS1 is connected to PF5 When PF5 line goes high then Slave will send values to the LCD display. If we get the first step correct – then everything else should happen automatically – provided we have set up the SPI interface correctly

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 4 / 24 Review -- Blackfin transmits 16 bits using MSB-first format over the MOSI line DB7, DB6, ………DB1, DB0 RS 1 – LCD data 0 – LCD instruction R/W 1 – Read from LCD 0 – Write to LCD 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 ) Now we care

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 5 / 24 LCD_Display (int, char*, char *); First attempt – may refactor later #include LCD_Display (int lcd, char * type, char *operation) { if (strcmp(type, “COMMAND”) == 0) { if (strcmp(operation, “CLEAR_SCREEN”) == 0) ClearScreen( ); if (strcmp(operation, “……..”) == 0) Do……..( ); } if (strcmp(type, “DATA”) == 0) { if (strcmp(operation, “DISPLAY_TEMPERATURE”) == 0) DisplayTemperature( ); else WriteLetter(operation[0]); // First character }

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 6 / 24 We need to toggle that E-flag (and wait) to make “slow” LCD work #define EN_LINE_HIGH 0x0100 #define EN_LINE_LOW 0x0000 #define ISDATA 0x400 ClearScreen( ) { WriteSPIASM(EN_LINE_HIGH | 0x0001); WaitABit(40 us); WriteSPIASM(EN_LINE_LOW | 0x0001); WaitABit(1.4 ms); WriteSPIASM(EN_LINE_HIGH | 0x0001); WaitABit(40 us); } WriteLetter(char letter) { WriteSPIASM(EN_LINE_HIGH | ISDATA | letter); WaitABit(40 us); WriteSPIASM(EN_LINE_HIGH | ISDATA | letter); WaitABit(40 us); WriteSPIASM(EN_LINE_LOW | ISDATA | letter); WaitABit(40 us); CursorMove( ); ?????? } // Just ONE routine to work -- to make Lab. 4 to work !!!!!!!!!!

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 7 / 24 SPI-Tests – Initialization Set_SPIregisters_ASM(ulong BAUD_SCALE) #include #define BAUD_SCALE 0x8000 // Make system slow so we can scope the data transfers TEST(SET_SPI_Registers, ConfigureSPIregisters) { WatchDataClass spi_reg(4, pSPI_BAUD, pSPI_CTL, pSPI_FLG, pSPI_STAT); WATCH_MEMORY_RANGE(spi_reg, (Set_SPIregisters_ASM(BAUD_SCALE)), READ_CHECK | WRITE_CHECK); // Warning – many of the SPI_STAT bits are W1C – write 1 to clear – DON”T write 0’s USHORTS_EQUAL(spi_reg.getFinalValue(0), BAUD_SCALE); USHORTS_EQUAL((spi_reg.getStartValue(1) | 0x01 | /* SPE | */ MSTR | CPOL | /* CPHA | */ SIZE), spi_reg.getFinalValue(1)); USHORTS_EQUAL((spi_reg.getStartValue(2) | FLS5), spi_reg.getFinalValue(2)); USHORTS_EQUAL(spi_reg.getStartValue(3), 1); // Reset value is 1 CHECK(spi_reg.getReadsWrites() == 5); // May be a different number in your code }

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 8 / 24 volatile bool transmit_empty; // FLAG / SEMAPHORE volatile unsigned short transmit_value; // MESSAGE TO ISR EX_INTERRUPT_HANDLER(SPI_ISR) { SPI_TDBR  transmit_value; transmit_empty = true; Clear the interrupt signal so don’t re-enter ISR } void WriteSPI(unsigned short int value ) { while (transmit_empty = = false) /* wait for a signal from the ISR to say ready for next */ ; transmit_empty = false; transmit_value  value; // Store the value as a message for ISR } Not the “best solution” (that needs DMA stuff) – but would it work????? WE KNOW WE DON’T NEED THIS LINE

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 9 / 24 Concept We write 16-bits (0xFF0A) into SPI_TDBR Hardware transfers this to SHIFT register SPI_TDBR now empty – new interrupt occurs 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

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 10 / 24 Can we write this sort of test to make things work on the SPI interface? EX_INTERRUPT_HANDLER(spi_ISR); TEST(WriteSPIValue, ConfigureSPIregisters) { InitSPI_ASM(0x800); register_handler(?????, SPI_ISR); Set_SIC_IMASK_ASM(0x2000); // Set the SIC_IMASK as we needed to do // in Lab. 3 to make the general purpose timer interrupts work StartSPI( ); WriteSPI(0x0A); // Connect SPI interface to LED’s on logic station WriteSPI(0xFF05);// Values should be there WriteSPI(0x0F0F); // Look at values on MOSI line with scope // SOMETHING should be there EVEN IF INVALID // Need to look at both MOSI and PF5 }

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 11 / 24 Things we DO and DON’T want to happen PF5 line MOSI signal 3 words transmitted WORD 1 RECEIVED BY SLAVE BUT NOT SENT ONTO LCD PF HIGH SLAVE IGNORES BLACKFIN PF LOW SLAVE LISTENS TO BLACKFIN WORD 2 RECEIVED BY SLAVE AND SENT TO LCD SLAVE SENDS COMMAND TO LCD WORD 3 IGNORED BY SLAVE AND NOT SENT ONTO LCD

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 12 / 24 SPI_registers Hardware Chap SPI Status register – Has SPI finished the transfer? void WaitWhileSPIF_ASM(low / high) Wait while SPI low (not finished)

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 13 / 24 volatile bool transmit_empty; // FLAG / SEMAPHORE volatile unsigned short transmit_value; // MESSAGE TO ISR EX_INTERRUPT_HANDLER(SPI_ISR) { SPI_TDBR  transmit_value; transmit_empty = true; Clear the interrupt signal so don’t re-enter ISR } void WriteSPI(unsigned short int value ) { while (*transmit_empty = = false) /* wait for a signal from the ISR to say ready for next */ ; WaitWhileSPIF(0x0); /* Wait for HARDWARE SIGNAL */ transmit_empty = false; transmit_value  value; // Store the value as a message for ISR } Not the “best solution” (that needs DMA stuff) – but would it work????? Don’t need this line LOOK FOR SPIF bit instead (SPI_FINISHED)

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 14 / 24 Would that really work? void WriteSPI(unsigned short int value ) { WaitWhileSPIF(0x0); /* Wait for HARDWARE SIGNAL */ transmit_value  value; // Store the value as a message for ISR } Possible RACE condition problem  Might WriteSPI( ) put many values into the transmit buffer before ANY are transmitted? Does it depend on how fast Blackfin is compared to SPI interface Answer: I don’t know till I try stuff and see if a problem.

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 15 / 24 PF5 line MOSI signal 3 words transmitted WORD 1 RECEIVED BY SLAVE BUT NOT SENT ONTO LCD WORD 2 RECEIVED BY SLAVE AND SENT TO LCD WORD 3 IGNORED BY SLAVE AND NOT SENT ONTO LCD

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 16 / 24 PF5 line MOSI signal 2 words transmitted WORD 1 RECEIVED BY SLAVE BUT NOT SENT ONTO LCD WORD 2 RECEIVED BY SLAVE AND SENT TO LCD If look at signal with an “ultra-high-speed” scope then can see PF line go high for “a very short period of time”. Blackfin is “too fast” for interface

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 17 / 24 Need to slow things down a bit or take different approach? void WriteSPI(unsigned short int value ) { WaitWhileSPIF(0x0); /* Wait for HARDWARE SIGNAL */ transmit_value  value; // Store the value as a message for ISR WaitAwhile(??? How-long is enough); // Is this the right location for the wait? // DO we need this instead (or perhaps -- as well as) to solve race conditions? // WaitWhileSPIF(0x1); /* Wait for HARDWARE SIGNAL */ } This is beginning to sound like “epi-cycles – on epi-cycles” as we work out how the planets go around the sun. It might (just work) for this laboratory but we should really be looking at letting the hardware worry about the timing Put all the messages in a long array Set DMA registers to point to start of array. Activate both SPI and DMA and let the Blackfin do the job. That is what it was designed for!!!!!!!!!!!!!

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 18 / 24 WORD 1 RECEIVED BY SLAVE AND SENT ONTO LCD WORD 2 RECEIVED BY SLAVE AND SENT TO LCD WORD 3 RECEIVED BY SLAVE AND SENT ONTO LCD VALUES GOING TO LCD

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 19 / 24 So do we think we are in good shape to get Lab. 4 started? Task 1 – same as Task 1 in Lab. 3 Set up the Lab4 and Lab4Test directories Make the Lab4.prj and Lab4Test projects Write a simple Lab4main to check that the Blackfin and the 50-pin cable are still working Check that all the Lab1, Lab2 and Lab3 tests work. Select “exclude from build” for Lab2 and Lab3 tests if you want. Remove the _FCT_Lab3.cpp file Don’t forget to “Refresh connections” using the GUI interface

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 20 / 24 Lets not tackle too many things at once. Show ability to recognize commands and data -- Task 2 extern volatile bool centigrade; extern volatile short int temperature; char *LCDcommands[ ] = { "COMMAND", "INIT_LCD", "COMMAND", "CLEAR_SCREEN", "COMMAND", "MOVE_TO_LINE_1", "COMMAND", "CLEAR_LINE_1", "DATA", "4", "DATA", "1", "DATA", "5", "COMMAND", "MOVE_TO_LINE_2", "COMMAND", "CLEAR_LINE_2", "DATA_TEMPERATURE", "TEMPERATURE_DISPLAY", NULL, NULL};

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 21 / 24 Lab 4 main( ) – first attempt Simulate the LCD screen int main( ) { long int switch_result = 0; Initialize_ProgrammableFlagsASM( ); InitializeLEDInterfaceASM( ); char **pt = LCDcommands; // Point to the start of the commands char *type_of_operation = NULL; // what needs to be done char *which_operation = NULL; centigrade = true; temperature = 40; while (*pt != NULL) { // While there are commands to do type_of_operation = *pt++; which_operation = *pt++; LCD_Display( LCD_SIMULATION, type_of_operation, which_operation); }

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 22 / 24 First attempt to get the LCD_Display to work void LCD_Display( int which_LCD_version, char *type_of_operation, char *which_operation) { char small_string[2]; small_string[1] = '\0'; // I used this when printing out the temperature if (strcmp(type_of_operation, "DATA_TEMPERATURE") == 0) { // Recursively use LCD_Display( ) to print out each digit of temperature // followed by a ‘C” or and “F” return; } if (which_LCD_version == LCD_SIMULATION) { printf(“Group name here %s %s\n", type_of_operation, which_operation); return; }

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 23 / 24 Task 3 – Test out the interface -- Lights Connect the special Blackfin interface (logic lab) CJ7 and CJ8 lines to the logic lab lights – make sure that the bit order and wires are correct, otherwise you will be paying $2 into the Zoo Christmas “support a family fund” Connect the MOSI, PF5 and CLK lines Download and run the program “SPILightstrial.dxe” The lights will flash from right-to-left if the wires are hooked up correctly If you press and release SW3, then the program will stop Later, when the LCD needs testing we will use this program again

7/14/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 24 / 24 Information taken from Analog Devices On-line Manuals with permission Information furnished by Analog Devices is believed to be accurate and reliable. However, Analog Devices assumes no responsibility for its use or for any infringement of any patent other rights of any third party which may result from its use. No license is granted by implication or otherwise under any patent or patent right of Analog Devices. Copyright  Analog Devices, Inc. All rights reserved.