Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network and Systems Laboratory nslab.ee.ntu.edu.tw.

Similar presentations


Presentation on theme: "Network and Systems Laboratory nslab.ee.ntu.edu.tw."— Presentation transcript:

1 Network and Systems Laboratory nslab.ee.ntu.edu.tw

2 Network and Systems Laboratory nslab.ee.ntu.edu.tw GPIO on MSP430 6 ports on MS430F1611 Port 1 Port 2 Port 3 Port 4 Port 5 Port 6 Each port has 8 pins Px.0 ~ Px.7

3 Network and Systems Laboratory nslab.ee.ntu.edu.tw Multiplexed Port pins are often multiplexed Means it may have more than one function Example: P1.0/TACLK It can be P1.0 GPIO Or it can be TACLK You must select the function you want

4 Network and Systems Laboratory nslab.ee.ntu.edu.tw Each pin can be configured as input or output When set to output You can configure it to be High: voltage is Vcc (Supply voltage) Low: voltage is GND (Ground) High: 3.3V Select Direction Low: 0V

5 Network and Systems Laboratory nslab.ee.ntu.edu.tw Input When you select a pin as input direction, a corresponding bit in peripheral register will Set to 0 when input voltage is low Set to 1 when input voltage is high High: 3.3V Low: 0V 1 0

6 Network and Systems Laboratory nslab.ee.ntu.edu.tw Interrupts Only P1 and P2 are interruptible For each pin in P1 and P2, you can enable or disable its interrupt Enable means it will detects interrupt Disable means nothing happen when interrupt occur

7 Network and Systems Laboratory nslab.ee.ntu.edu.tw How to Detect Interrupts For GPIO, interrupt is detected when a transition occur Low to high transition: High to low transition: You must define which one you want to detect 0 V 3.3 V 0 V 3.3 V

8 Network and Systems Laboratory nslab.ee.ntu.edu.tw Interrupt Flag When the MCU detects an interrupt A corresponding bit in peripheral register will set to 1 Branch to ISR You must clear the GPIO interrupt flag in software Means you must set the bit to 0 or the program will re-enter the ISR again

9 Network and Systems Laboratory nslab.ee.ntu.edu.tw GPIO Registers Each GPIO port has four registers Input: P x IN Output: P x OUT Direction: P x DIR Port Select(function select): P x SEL P1 and P2 have three more Interrupt flag: P x IFG Interrupt edge select: P x IES Interrupt enable: P x IE Each register is 8-bit long x represent the port number

10 Network and Systems Laboratory nslab.ee.ntu.edu.tw How to Select Function You want to select this pin as GPIO(P1.0) function The register related to function select Port Select(function select): P x SEL This is port 1, so the related register is P1SEL From user guide

11 Network and Systems Laboratory nslab.ee.ntu.edu.tw How to Select Function P1SEL is 8-bit long Each bit corresponding to a pin in the port P1SEL xxxxxxxx 07 P1.0/TACLK P1.1/TA0 P1.2/TA1 P1.3/TA2 P1.4/SMCLK P1.5/TA0 P1.6/TA1 P1.7/TA2

12 Network and Systems Laboratory nslab.ee.ntu.edu.tw How to Select Function You want select P1.0/TACLK as P1.0 Set the corresponding bit to 0 In C: P1SEL = P1SEL & 0xFE; P1SEL xxxxxxxx 07 P1.0/TACLK P1.1/TA0 P1.2/TA1 P1.3/TA2 P1.4/SMCLK P1.5/TA0 P1.6/TA1 P1.7/TA2 P1SEL xxxxxxx0 07

13 Network and Systems Laboratory nslab.ee.ntu.edu.tw Setting Bits P1SEL = P1SEL & 0xFE; P1SEL &= 0xFE; Usually, we use hexadecimal in setting registers 0xFE = 11111110 (binary number) Why P1SEL &= 0xFE; Why not P1SEL = 0xFE; The other registers are similar check user guide Hexadecimal

14 Network and Systems Laboratory nslab.ee.ntu.edu.tw GPIO Interrupt All P1 pins source a single interrupt vector, and all P2 pins source a different single interrupt vector. Interrupts generated by P1.0, P1.1, …, P1.7 all go to same ISR How do you know which one generate the interrupt check interrupt flag

15 Network and Systems Laboratory nslab.ee.ntu.edu.tw Hardware LEDs Switches Keypad

16 Network and Systems Laboratory nslab.ee.ntu.edu.tw LEDs This is a typical connection When P1.1 set to high DVcc = V P1.1 no current flow When P1.1 set to low V P1.1 = 0 Current flow through, turn on the LED GPIO can use as an On/Off control DVcc V anode V cathode R

17 Network and Systems Laboratory nslab.ee.ntu.edu.tw Control LEDs Look at Taroko schematic which pins the LEDs connected to These pins should be input direction or output direction? How to set these pins to high (or low)

18 Network and Systems Laboratory nslab.ee.ntu.edu.tw Will This Work Maybe, but you shouldn’t do this V anode V cathode R

19 Network and Systems Laboratory nslab.ee.ntu.edu.tw Max Current Source/Sink Each pin has a maximum amount of current it can provide(source) or accept(sink) For MSP430 Max source: 6mA Max sink: 6mA Usually it can sink more current than it can source You cannot use those pin as a power source (or sink) for any sensor/circuit directly

20 Network and Systems Laboratory nslab.ee.ntu.edu.tw Transistors One of the fundamental building block of ICs Two type: NPN, PNP B : Base C : Collector E : Emitter We will talk about NPN transistor most commonly used

21 Network and Systems Laboratory nslab.ee.ntu.edu.tw Functional Model A base current I B flows only when the voltage V BE across the base-emitter junction is 0.7V or more Ic = h FE × I B (h FE is current gain) The collector-emitter resistance R CE is controlled by the base current I B : I B = 0 R CE = infinity transistor off I B small R CE reduced transistor partly on I B increased R CE = 0 transistor full on ('saturated')

22 Network and Systems Laboratory nslab.ee.ntu.edu.tw Transistor as An On/Off Switch Application Circuit  Load is turn on when chip output is high Choose a proper transistor and base resistor R B

23 Network and Systems Laboratory nslab.ee.ntu.edu.tw How To Choose Transistor Two parameter: Ic and h FE Ic(max) must be larger than I load (Ic) Ic = h FE × I B h FE(min) > 5 x ((Ic) /(maximum output current from the chip)) R B R B = (Vcc × h FE ) / (5 × Ic) choose the nearest standard value resistor

24 Network and Systems Laboratory nslab.ee.ntu.edu.tw Switches Operation Open: A and B are not connected in normal state Close: When you press the button, A and B are connected Typical circuit When the switch is open, voltage of USERINT stay at high When the switch is close, voltage of will be low A B

25 Network and Systems Laboratory nslab.ee.ntu.edu.tw Pull-up Resistor R4 is a pull-up resistor keep USERINT at high What if we don’t have R4 When it is open, USERINT is still high When it is close Short circuit USERINT

26 Network and Systems Laboratory nslab.ee.ntu.edu.tw Typical Value Typical value of pull-up resistor 10K ohm, 47K ohm, 100K ohm Amount of current flow through when it close I = V/R; Vcc = 3.3V, R = 10K ohm I = 0.00033A = 330 μA 330 μA, does it matter for some type of switch, it is ok close time very short but not all, eg. reed switch

27 Network and Systems Laboratory nslab.ee.ntu.edu.tw Value of Pull-up To save power, can we use very large pull-up resistor? ans: No

28 Network and Systems Laboratory nslab.ee.ntu.edu.tw Impedance Resistance: R = V/I relation ship between the magnitude of the voltage and current Impedance: Z = V/I (there are complex number) relation ship between the magnitude and phase of the voltage and current

29 Network and Systems Laboratory nslab.ee.ntu.edu.tw Input Impedance Z RiRi R1R1 RiRi Vcc This is a simplified analysis, we consider impedance as a resistance. Impedance is more complex than a simple resistance

30 Network and Systems Laboratory nslab.ee.ntu.edu.tw Resistors in series R i is the input impedance of MSP430 GPIO pin TI didn’t specify its value but it should be larger than 10M ohm R 1 is pull-up resistor if R 1 is too large – R 1 = R i then V MCUpin = Vcc / 2 it is no longer a high state R1R1 RiRi Vcc V MCUpin

31 Network and Systems Laboratory nslab.ee.ntu.edu.tw Debounce Capacitor C9 is a debounce capacitor Bounces It could generate more than one interrupts when the switch is pressed

32 Network and Systems Laboratory nslab.ee.ntu.edu.tw HW/SW debounce Hardware debounce Capacitor will charge when the switch is open, and it will discharge when the switch is close (pressed) Pros: smooths the line Cons: increase the response time Software debounce Delay some time in the ISR How long you have to try out

33 Network and Systems Laboratory nslab.ee.ntu.edu.tw Keypad This is a 3x4 matrix keypad When you press a button, a pin in X and a pin in Y is connected How to interface to MSP430?

34 Network and Systems Laboratory nslab.ee.ntu.edu.tw Today’s Labs 1. Flash a LED on Taroko 2. Toggle a LED when UserInt switch on Taroko pressed 3. Control on/off of a LED by UserInt switch, control another by reed switch 4. (Extra Credit) Connected a 3x4 Keypad to Taroko, flash the LEDs RedGreenYellow Flash once Flash twice

35 Network and Systems Laboratory nslab.ee.ntu.edu.tw JTAG Driver C:\Program Files\IAR Systems\Embedded Workbench Evaluation 4.0\430\drivers\TIUSBFET\WinXP

36 Network and Systems Laboratory nslab.ee.ntu.edu.tw IAR Setting

37 Network and Systems Laboratory nslab.ee.ntu.edu.tw IAR Setting

38 Network and Systems Laboratory nslab.ee.ntu.edu.tw

39 Network and Systems Laboratory nslab.ee.ntu.edu.tw

40 Network and Systems Laboratory nslab.ee.ntu.edu.tw

41 Network and Systems Laboratory nslab.ee.ntu.edu.tw

42 Network and Systems Laboratory nslab.ee.ntu.edu.tw

43 Network and Systems Laboratory nslab.ee.ntu.edu.tw

44 Network and Systems Laboratory nslab.ee.ntu.edu.tw

45 Network and Systems Laboratory nslab.ee.ntu.edu.tw


Download ppt "Network and Systems Laboratory nslab.ee.ntu.edu.tw."

Similar presentations


Ads by Google