Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual.

Similar presentations


Presentation on theme: "Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual."— Presentation transcript:

1 Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual

2 What is a switch PRESS DOWN TO CLOSE
SPRING TO CAUSE SWITCH TO OPEN AFTER PUSH TO CLOSE SWITCH OUTPUT SWITCH INPUT

3 Normally one side of switch is grounded, the other side connected to microprocessor GPIO input
INPUT IS ????? FLOATING BLACKFIN INPUT IS 0V GPIO LINES PF8, PF9, PF10, PF11 GROUND (0V)

4 Normally one side of switch is grounded, the other side connected to microprocessor GPIO input
INPUT IS ????? FLOATING BLACKFIN INPUT IS 0V GPIO LINES PF8, PF9, PF10, PF11 GROUND (0V)

5 One side of the switch must be pulled “softly” to 3 V / 5V (pull up resistor)
10k “Pull-up” resistor BLACKFIN INPUT IS 5V INPUT IS 0V GPIO LINES PF8, PF9, PF10, PF11 GROUND (0V)

6 Blackfin has a GPIO data register
16 GPIO lines come into the register Registers are based on flip-flops to store whether the input is 3V (high) or zero (low) 16 flip flops put together make a register The GPIO data register is memory mapped so you can’t access it directly, you must “treat it as if it is memory” When you “read” from the GPIO register, you cause a “load” of the input values into the flip-flop and out onto the data bus

7 Registers used to control PF pins
Flag Data register (FIO_FLAG_D) Used to read the PF bits as an input -- (1 or 0) Need to read pins PF11 to PF8 ONLY , ignore all other pins values

8 What we know SW1 is connected to PF8 SW2 is connected to PF9
The other pins in the GPIO interface are used for “other” purposes and MUST not have their values changed

9 What we want to do Read the GPIO data register
Return ONLY the values in pins 8 to 11 which means removing (masking out) the other values Value read from data register = 0x4723 We only want to get the bits 0x0700 (SW1, SW2, SW3) Value read from data register = 0x4023 We only want to get the bits 0x0000 (no switches) Value read from data register = 0x4823 We only want to get the bits 0x0800 (SW4)

10 What we have to code MASK = 1 for bits we keep, 0 for bits removed
MASK = 0x0F00 Value read from data register = 0x4723 (PF8, 9, 10) We only want to get the bits 0x0700 Result = value & MASK (and operation) Value read from data register = 0x4023 (none) We only want to get the bits 0x0000 Value read from data register = 0x4823 (PF11) We only want to get the bits 0x0500

11 So the code required is #include <blackfin.h> .section program;
.global _ReadGPIOFlagsASM; _ReadGPIOFlagsASM: P0.L = lo(FIO_FLAG_D); P0.H = …… R0 = W[P0] (Z); #define AND_MASK 0x0F00; R1 = AND_MASK; R0 = R0 & R1; _ReadGPIOFlagsASM.END: RTS;

12 DOES NOT WORK We have not “initialized” the GPIO interface
“Initialize” means “prepare to make work” #include <blackfin.h> .section program; .global _ReadGPIOFlagsASM; _ReadGPIOFlagsASM: P0.L = lo(FIO_FLAG_D); P0.H = …… ………; R0 = R0 & R1; _ReadGPIOFlagsASM.END: RTS;

13 Initialize the GPIO interface
Turns the interrupts OFF for PF8 to PF11 WITHOUT changing the interrupts for the other pins Set the POLARITY register so that a 1 coming into pins PF8 to PF11 is read as a HIGH (1) without changing the behaviour of the other GPIO pins. Etc etc

14 Initialize the GPIO interface
Set the DIRECTION register so that PF8 to PF11 pins are INPUT without changing the behaviour of the other GPIO pins. IF DONE INCORRECTLY CAN BURN OUT THE CHIP After all other initialization steps are complete Set the ENABLE register so that pins PF8 to PF11 work without changing the behaviour of the other GPIO pins

15 So the code required is #include <blackfin.h> .section program;
.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: CALL TurnInterruptsOff_PF8to11; CALL SetPolarity_PF8to11; CALL OtherStuff_PF8to11; CALL SetDirection_PF8to1; CALL Enable__PF8to11; _InitGPIOFlagsASM.END: RTS;

16 Wrong code #include <blackfin.h> .section program;
.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: CALL TurnInterruptsOff_PF8to11; // CALL means set RETS register // to point to instruction after CALL // RETS = next: next: CALL SetPolarity_PF8to11; next2: CALL OtherStuff_PF8to11; Next3: CALL SetDirection_PF8to1; Next4: CALL Enable__PF8to11; _InitGPIOFlagsASM.END: RTS; // This means JUMP RETS // What line of code is executed? // “where does code jump to?

17 Correct code #include <blackfin.h> .section program;
.global _InitGPIOFlagsASM; _InitGPIOFlagsASM: LINK 16; // Save (write) RETS to the stack CALL TurnInterruptsOff_PF8to11; // CALL means set RETS register // to point to instruction after CALL // RETS = next: next: CALL SetPolarity_PF8to11; next2: CALL OtherStuff_PF8to11; Next3: CALL SetDirection_PF8to1; Next4: CALL Enable__PF8to11; UNLINK; // Recover (get back) RETS from the stack _InitGPIOFlagsASM.END: RTS; // This means JUMP RETS // What line of code is executed? // “where does code jump to?

18 Other GPIO Flip flops FIO_MASKA_D and FIO_MASKB_D
If bit X = 1, tell processor to cause interrupt when FIO_FLAG_D bit X is active

19 CALL TurnInterruptsOff_PF8to11;
#include <blackfin.h> .section program; .global _TurnInterruptsOff_PF8to11; _ TurnInterruptsOff_PF8to11: P0.L = lo(FIO_MASK_A); P0.H = …… R1 = 0; W[P0] = R0; // DO same thing for FIO_MASK_B TurnInterruptsOff_PF8to11: RTS

20 P0.L = lo(FIO_MASK_A); P0.H = …… R1 = 0; W[P0] = R0;
This puts a 0 in every bit and turns ALL interrupts off – not just bits 8 to 11

21 CALL TurnInterruptsOff_PF8to11;
#include <blackfin.h> .section program; .global _TurnInterruptsOff_PF8to11; _ TurnInterruptsOff_PF8to11: P0.L = lo(FIO_MASK_A); P0.H = …… R0 = W[P0] (Z); // Read all the bits #define MASK_NOCHANGE_VALUES 0xF0FF R1 = MASK_NOCHANGE_VALUES R0 = R1 & R1; // Bits 8 to 11 zero W[P0] = R0; // But other bits still the same // DO same thing for FIO_MASK_B TurnInterruptsOff_PF8to11: RTS

22 Another GPIO register we need to set correctly

23 Another flip-flop group controls whether the flip-flop outputs follow the flip-flop inputs or are “high impedance” – off – no useful value

24 CALL EnablePins_PF8to11;
#include <blackfin.h> .section program; .global _EnablePins_PF8to11; _ EnablePins_PF8to11: P0.L = lo(FIO_INEN); P0.H = …… #define MASK_CHANGE_VALUES 0x0F00; R1 = MASK_CHANGE_VALUES W[P0] = R1; EnablePins_PF8to11.END: RTS WRONG: True this enables bits 8 to 11, but it also DISABLES all the other bits Need to use “OR” instruction after reading the enable register

25 A key issue with GPIO is whether a pin is to act as an input device (bringing things in from the outside world into the Blackfin) or as an output device (sending things from the Blackfin to the outside world)

26 Flag Direction register (FIO_DIR)
Why do you need to know how to do read (load) and write (store) on internal registers? Flag Direction register (FIO_DIR) Used to determine if the PF bit is to be used for input or output WARNING SMOKE POSSIBLE ISSUE Need to set pins PF11 to PF8 for input, leave all other pins unchanged

27 Making sure that the FIO_DIR is correct for LAB
Making sure that the FIO_DIR is correct for LAB. 1 – NOTE may need to change for later labaoratories Write the Blackfin assembly language instruction(s) to load the address of the internal programmable flag FIO_DIR register into pointer register P1 – then SET the Blackfin PF lines to act as inputs #include <blackfin.h> P1.L = lo (FIO_DIR); P1.H = …. // Check the requirements – need to have all input // Manual says “setting a line for input means setting bit values to 0” R0 = 0; W[P1] = R0; // This changes “All pins” ssync; // Force Blackfin to do the write (store) NOW not later Design Error “Changes all pins

28 Notice that previous slide WARNS you about a design error in the code
We can’t do things this way as it changes all the bits in the 16 flip-flops and we only want to change 4 values in the flip-flops The same design error is introduced into Lab. 1 Task 3 However, the same design error is found during the TDD tests – provided to look at the test code to see what was being tested

29 These tests DONOT find the design error

30 These tests DO find the design error and in fact explain to you why it is likely that your tests have failed. But you have to read it

31 Echoing the switches to the LED Code in main( ) – written in C++
int main( ) { InitializeGPIOInterface( ); // Check Lab. 1 for “exact name needed” InitializeFlashLEDInterface( ); // Check Lab. 1 for “exact name needed” #define SWITCHBITS 0x0F // Look in MIPs notes about // using a mask and the // AND bit-wise operation // to select “desired bits” while (1) { // Forever loop int GPIO_value = ReadBlackfinGPIOFlagsASM ( ); int desired_bits = GPIO_value & SWITCHBITS; int LED_light_values = desired_bits >> 8; // Bits in wrong position WriteFlashLEDLights(LED_light_values); // to display on LEDS }

32 Building a radio controlled car 4 Threads at least
SWITCHES ON FRONT PANEL “INPUT COMMANDS: LED LIGHTS ON FRONT PANEL “CONTROLSIGNALS TO RF TRANS: PROGRAMMABLE FLAGS LED-CONTROLREGISTER FIO_FLAG_D Register EBIU INTERFACE YOUR PROGRAM RUNNING ON THE BLACKFIN int ReadSwitches( ) void WriteLED(int ) ProcessDataASM( ) subroutine VOICE A/D D/A EAR PHONES A/D D/A Interrupt routine

33 LEDs connected to FLASH port
BACK FORWARD RIGHT LEFT ??? CONTROL ON Might be connected to other things DON’T CHANGE BEHAVIOUR Blackfin BF533 I/O


Download ppt "Lab. 1 – GPIO Pin control Using information ENEL353 and ENCM369 text books combined with Blackfin DATA manual."

Similar presentations


Ads by Google