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.

Slides:



Advertisements
Similar presentations
Anurag Dwivedi Rudra Pratap Suman. Scope of Communica tion Telephones and Cell Phones.
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.
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.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
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.
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.
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.
Blackfin BF533 EZ-KIT Control The O in I/O Activating a FLASH memory “output line” Part 2.
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.
Blackfin BF533 EZ-KIT Control The O in I/O
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.
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.
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
Peripherals and their Control An overview of industrially available “peripheral devices” that use “pulse-width modulation” for information passing. Review.
Input Laboratory: GPIO Pin control needed to have the Blackfin accept your commands Re-uses information from ENEL353 and ENCM369 courses and text books.
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
1-1 Embedded Network Interface (ENI) API Concepts Shared RAM vs. FIFO modes ENI API’s.
Moving Arrays -- 1 Completion of ideas needed for a general and complete program Final concepts needed for Final Review for Final – Loop efficiency.
13-Nov-15 (1) CSC Computer Organization Lecture 7: Input/Output Organization.
PPI-8255.
OCRP RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
Handling multiple input signals Version #2 – co-operative scheduler Version #3 – pre-emptive scheduler.
بسم الله الرحمن الرحيم MEMORY AND I/O.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
“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,
Lab3 -- Lab 4 Design and implementation details on the way to a valid SPI-LCD interface driver.
Serial mode of data transfer
Tutorial Introduction
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.
Serial Communication Interface: Using 8251
SPI Compatible Devices
Thermal arm-wrestling
SPI Protocol Sepehr Naimi
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
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
Thermal arm-wrestling
Explaining issues with DCremoval( )
Lab3 -- Lab 4 Review Design and implementation details on the way to a valid SPI-LCD interface driver.
Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.
Independent timers build into the processor
Thermal arm-wrestling
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:

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

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 2 / 29 To be tackled today Review -- What is SPI? Review -- What is the SPI “master slave” relationship? Review -- How do you send commands from the Blackfin to a LCD device? Review -- What commands are necessary to control the LCD device -- HD44780? Just 4 functions to be developed Done thing like the first 3 in Lab. 1, 2 and 3 – only hassle need to read the manual void InitializeSPI_ASM(unsigned short int SPI_baudrate); void StartSPI_ASM(void); void Set_SIC_IMASK_ASM(unsigned long int SIC_IMASK_value); void WriteSPIASM(unsigned short int value) MMMMMMM ???????????????

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 3 / 29 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

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 4 / 29 Review -- Lab. 4 concept – Using an SPI interface to an LCD screen SPI_TDBR Blackfin Processor SPI_RXBR LCD SCREEN CJ7 / CJ8 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

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 5 / 29 Review -- Lab. 4 interface From Blackfin SPI lines (MOSI, CLK, PF5)

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 6 / 29 Review 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 InitializePFLinesASM( ) and other routines and Tests? When do we activate the chip-select line, and how long for? How do we know when LCD is ready for next character – do we poll a bit and wait till ready, or can it be done in the background? In Lab 4 – probably just “wait-long enough” How do we stop multiple commands from being accidentally sent to LCD? -- too many cursor moves etc We know answer to this one – activate the EN* line on the LCD

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 7 / 29 Review -- Lab Essentials of the Blackfin – LCD interface software char HipHipArray[ ] = “Merry Christmas to all”; SetUp_SPI_Interface(Baud_Rate); // Configure the SPI interface // Set up register_handler( ) and SIC_IMASK LCD_Display (WHICH_LCD, “CONTROL”, “CLEAR_SCREEN”); UseFixedTimeASM(Enough_Time_For _LCD_To_Work); for (int count = 0; count < strlen(HipHipArray); count++) { LCD_Display (WHICH_LCD, “DATA”, HipHipArray[count]); // Transmit the information we want from the array // one character at a time UseFixedTimeASM(Enough_Time_For _LCD_To_Work); }

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 8 / 29 Review -- 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 }

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 9 / 29 Blackfin transmits 16 bits with THIS 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 ) We don’t care at the moment THIS IS NEW STUFF We just want “something” valid on MOSI line

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 10 / 29 Start with something we know how to do – PF5 as Output signal Need to set PF5 as output But if we change Initialize_ProgrammableFlagsASM(); too much else MIGHT need changing TEST(FIO_DIR, DEVELOPER_TEST) { TEST_LEVEL(10); WatchDataClass FIO_DIR_access (1, (unsigned short *) pFIO_DIR); WATCH_MEMORY_RANGE(FIO_DIR_access, Initialize_ProgrammableFlagsASM()); unsigned short int expected_result = 0x0000; CHECK(FIO_DIR_access.getFinalValue(0) == expected_result); }

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 11 / 29 Start with something we know how to do – PF5 changed to Output Solution – use Initialize_ProgrammableFlagsASM(); then change the direction with new function void ChangePFtoOutput(int which_pins ) #define PF5 0x0020 // Check this is correct TEST(CHANGE_FIO_DIR, DEVELOPER_TEST) { TEST_LEVEL(10); Initialize_ProgrammableFlagsASM(); int oldFIO_DIR = *pFIO_DIR; // Use C++ to read FIO_DIR register WatchDataClass FIO_DIR_access (1, (unsigned short *) pFIO_DIR); WATCH_MEMORY_RANGE(FIO_DIR_access, ChangePFtoOutput(PF5 )); unsigned short int expected_result = oldFIO_DIR | PF5; Nothing else changed CHECK(FIO_DIR_access.getFinalValue(0) == expected_result); }

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 12 / 29 #include P1.L = lo (FIO_DIR); P1.H = hi (FIO_DIR); old_value_R1 = W[P1] (Z); // Get old value -- unsigned new_value_R2 = old_value_R1 | which_pins_R0 // INPAR1 in R0 W[P1] = new_value_R2; ssync; // Force Blackfin to do the write (store) NOW not later void ChangePFtoOutput(int which_pins ) Make sure nothing else changes in FIO_DIR – so read, then OR, then write

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 13 / 29 Blackfin interface details More slave side Blackfin side

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

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 15 / 29

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 16 / 29 SPI_registers -- Hardware Chap. 10 SPI_BAUD – We want to be able to change this 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) FLS5 bit – activates PF5 as slave select line FLG5 bit – could be used by us to control value of PF5 line 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 and the FLG5 bit is ignored” SOUNDS GOOD TO ME -- except what’s a CPHA? NEED TO WATCH FOR THIS FURTHER THROUGH THE MANUAL

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 17 / 29 SPI-registers -- more SPI_STAT – SPI Status register Has some read only bits Has some “write 1 to clear” sticky bits which are set when error condition occurs Need 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 did inside the core timer and general purpose timer registers

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 18 / 29 Status register information RO and W1C bits

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 19 / 29 ???? ????

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 20 / 29 SPI_CTL register 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 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

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 21 / 29 SPI_CTL register Things we still don’t understand SZ – send zeros (or last word again) when SPI_TDBR is empty causes what to happen? Sending zeros sounds bad as that means the EN* line will go low (zero) on the interface and the LCD might think it has received another command! CPOL – clock polarity Means what – and do we care? CPHA – Clock Phase When CPHA = 1, slave select controlled by user software When CPHA = 0, slave select controlled by SPI hardware MURPHY’S RULE – any bit whose function is not obvious will be the key of whether you get the interface to work or not 

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 22 / 29 Figure VALID slave load on signal transition VALID DATA STORED INVALID slave load on signal transition INVALID DATA STORED SLAVE DATA IS LOADED ON L-to-H CLOCK TRANSITION Different than Slave is SELECTED when PF5 = 0

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 23 / 29 We are now at the stage where we can do some experimenting with the hardware We know that the following pins are “key” to the operation of the SPI interface. MOSI – this will show the data being transmitted from the SPI interface PF5 – chip select line When this is pulled low, then the slave will accept any data being transmitted, otherwise data is ignored When this goes – low to high – then the serial data transmitted to the slave is “latched” (converted into a parallel signal that is then sent to LCD as a data or a command request. Place scope probes on these lines

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 24 / 29 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, InitializeSPI_ASM (BAUD_SCALE)); // 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() == 6); // Depends on how you code InitializeSPI_ASM( ); }

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 25 / 29 Can we write this sort of test to make things work on the SPI interface? Don’t even worry about LCD working! EX_INTERRUPT_HANDLER(spi_ISR); TEST(WriteSPIValue, ConfigureSPIregisters) { InitSPI_ASM(0x8000); 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 WRONG // Need to look at both MOSI and PF5 }

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

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 27 / 29 volatile bool transmit_empty; // SPI interface ready for next value volatile unsigned short transmit_value; // Value to transmit over SPI 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 } Would this sort of code work to transmit values over the MOSI line !!!!!! WE KNOW WE DON’T NEED THIS LINE

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 28 / 29 Is this approach a better solution Still a work in progress !!!!!! ClearScreenASM( ) { while (transmit_empty = = false) /* wait for signal from ISR */ ; transmit_empty = false; transmit_value  0x0001; // Store the clear screen command } WriteLetterASM(char letter) { while (transmit_empty = = false) /* wait for signal from ISR */ ; transmit_empty = false; transmit_value  0x200 | letter; Call CursorMoveASM; // Move cursor to place next letter or not??????? } Change to C++ programs as no longer talking directly to the hardware ClearScreen( ) { WriteSPIASM(0x0001); } WriteLetter(char letter) { WriteSPIASM(0x0200 | letter); Call CursorMoveASM} CursorMove ( ) {WriteSPIASM( 0x????); } etc

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 29 / 29 No – We need to toggle that E- flag as well to make LCD work #define EN_LINE_HIGH 0x0100 #define EN_LINE_LOW 0x0000 #define ISDATA 0x0400 ClearScreen( ) { WriteSPIASM(EN_LINE_HIGH | 0x0001); WriteSPIASM(EN_LINE_LOW | 0x0001); WriteSPIASM(EN_LINE_HIGH | 0x0001); } WriteLetter(char letter) { WriteSPIASM(EN_LINE_HIGH | ISDATA | letter); WriteSPIASM(EN_LINE_HIGH | ISDATA | letter); WriteSPIASM(EN_LINE_LOW | ISDATA | letter); CursorMove( ); ?????? // Do we need to do this? } // Just ONE routine to work one to get Lab. 4 to work !!!!!!!!!!

6/2/2015 SPI and LCD, Copyright M. Smith, ECE, University of Calgary, Canada 30 / 29 Tackled today Review -- What is SPI? Review -- What is the SPI “master slave” relationship? Review -- How do you send commands from the Blackfin to a LCD device? Review -- What commands are necessary to control the LCD device -- HD44780? Just 4 functions Done thing like the first 3 in Lab. 1, 2 and 3 – only hassle need to read the manual void InitializeSPI_ASM(unsigned short int SPI_baudrate); void StartSPI_ASM(void); void Set_SIC_IMASK_ASM(unsigned long int SIC_IMASK_value); void WriteSPIASM(unsigned short int value) MIGHT NOT BE SO BAD AFTER ALL