NXP PowerPoint template _Title_ Template for presentations _Subtitle_ by rt3463df

VIEWS: 9 PAGES: 41

									Industrial Reference Design Platform
I2 C

Developed by the TSC Americas




Release 1.0
I2C-Bus
Introduction
• I²C-bus = Inter-Integrated Circuit bus
• Bus developed by Philips in the early 80’s
• Simple bi-directional 2-wire bus:
    – serial data (SDA)
    – serial clock (SCL)
• Has become a worldwide industry standard and used by all
  major IC manufacturers
• Multi-master capable bus with arbitration feature
• Master-Slave communication; two-device only communication (generally)
• Each IC on the bus is identified by its own address code
• The slave can operate as a
    – receiver (slave – receiver)
    – transmitter (slave – transmitter)

                                                                                            2
                                                             TSC Americas – IRD Platform – I2C
I2C-Bus
START and STOP Conditions

Question: What is wrong with this figure?




                                                                           3
                                            TSC Americas – IRD Platform – I2C
I2C-Bus
START and STOP Conditions




Start Condition - a HIGH to LOW transition on the SDA line while SCL
is HIGH

Stop Condition - a LOW to HIGH transition on the SDA line while SCL is
HIGH


                                                                                        4
                                                         TSC Americas – IRD Platform – I2C
I2C-Bus
Data Transfer




           Data    Acknowledge




• During data transfer, SDA must be stable when SCL is High
• Each byte has to be followed by an acknowledge bit
• Number of bytes transmitted per transfer is unrestricted
• If a slave can’t receive or transmit another complete byte of data, it
  can hold the clock line SCL LOW to force the master into a wait state

                                                                                            5
                                                             TSC Americas – IRD Platform – I2C
I2C-Bus
Acknowledge and Not Acknowledge
The I2C specification says:
Data transfer with acknowledge is obligatory. The receiver must pull down
the SDA line during the acknowledge clock pulse so that it remains stable
LOW during the HIGH period of this clock pulse.

However, there are a few scenarios where there is not an acknowledge
(SDA staying HIGH). Which ones?

1. A receiver with the address is not present in the I2C bus
2. The receiver is performing real-time tasks and it cannot process the
   received I2C information
3. The receiver is the master and wants to take control of SDA line again in
   order to generate a STOP command. The slave transmitter MUST then
   release the SDA line when it sees the NACK so the master can send the
   STOP command.

                                                                                          6
                                                           TSC Americas – IRD Platform – I2C
I2C-Bus
Key Parameters
                                                     Fast          High
                             Standard    Fast
                                                     Mode         Speed
                               Mode      Mode
                                                     Plus          Mode
               Bit Rate
                             0 to 100   0 to 400   0 to 1000   0 to 1700          0 to 3400
                (kb/s)
             Max Load
                                400       400         550         400                  100
                  (pF)
             Rise time
                               1000       300         120         160                    80
                  (ns)
                 Noise
                                 -         50         10          10                     10
             filter (ns)

                 Rise Time
  VDD
  VIH                                                                           0.7xVDD




   VIL                                                                           0.3xVDD
   VOL                     0.4 V @ 3 mA Sink Current
                           0.4 V @ 20 mA Sink Current (Fm+)
  GND

                                                                                                      7
                                                                       TSC Americas – IRD Platform – I2C
I2C-Bus
Hardware architecture

                              Pull-up resistors
                              Typical value 2 k to 10 k




                        SCL   Open Drain structure (or
                              Open Collector)
                              Pull-down transistor required
                              on SDA but not on SCL


                                       10 pF Max
                                        I/O Cap




                                                                                      8
                                                       TSC Americas – IRD Platform – I2C
I2C-Bus
Pull-up resistors


How do you calculate pull-up resistor values ?




                                                                                9
                                                 TSC Americas – IRD Platform – I2C
I2C-Bus
Pull-up resistor value calculation
Minimum value
There is a minimum resistor value determined by the I²C spec limit of 3 mA.
R = (Vddmax – Volmax)/ 0.003A
Example: using a 5±0.5 V bus: R = (5.5V – 0.4V)/ 0.003A = 1.7 kΩ

Maximum value
Determined by the I²C-bus rise time requirements:
V(t1) = 0.3*Vdd = Vdd (1–1/et1/RC); then t1 = 0.3566749*RC
V(t2) = 0.7*Vdd = Vdd (1–1/et2/RC); then t2 = 1.2039729*RC
          t = t2–t1 = 0.8472979*RC
For standard-mode I²C-bus: t = rise time = 1000ns (1 s)
          so… RC = 1180.2 ns

Example: at a bus load of 400 pF: Rmax = 2.95 kΩ
For fast-mode:
         I²C-bus rise time = 300 ns @ 400 pF: Rmax = 885 Ω

                                                                                                 10
                                                                   TSC Americas – IRD Platform – I2C
I2C-Bus
Addressing           c       I/O      A/D        LCD   RTC     c II
                                       D/A

           SCL
           SDA
                                                                        A0
                              10100 1 1                                 A1     EEPROM
                                                                        A2
                              1 0 1 0 A2A1A0R/W
                                                                        New devices or
                               Fixed Hardware                           functions can be
                                     Selectable                         easily “clipped” on
                                                                        to an existing bus!
• Each device is addressed individually by software
• Unique address per device: fully fixed or with a programmable part through
  hardware pin(s)
• Programmable pins mean that several of the same devices can share the
  same bus
• Address allocation coordinated by the I2C-Bus committee
• 112 different addresses max with the 7-bit format (others reserved)
• 10-bit format use a 2 byte message: 1111 0A9A8R/W + A7A6A5A4A3A2A1A0

                                                                                               11
                                                                 TSC Americas – IRD Platform – I2C
 Multi Master Mode - Clock Synchronization
    Master 1                                Vdd              Master 2                          T1
                                                                                     TL1        TH1
  CLK 2                                                           CLK 1
  TL2, TH2                          SCL                          TL1, TH1                                     T2
                                   TL, TH
                                                                                                    TL2                     TH2
                        Counting TL1 done
                  Count     Wait State
                   TL1   TL2 still counting     Count TH1
                                                                                                          Internal Counters
CLK1                                                                                                      count the Low
   0
                                                                                                          and High times
                           Count TL2           Count TH2
                                                                                                          (TL1, TH1) and (TL2,
CLK2
                                                                                                          TH2)
   0
                 Reset Counter High TH2
                 Start Counting TL2   3                                          3
                     2   Counting TL2 done                             2
                         Start Counting TH2
SCL                      SCL goes High
   0                                              4                                        4
                    1                  Start Counting TH1          1
             Counting TH1 done                              Counting TH1 done
             Start Counting TL1                             Start Counting TL1
             SCL goes Low                                   SCL goes Low         • TL = longest TL = max (TL1, TL2 ,TLn )
                            TL = TL2              TH = TH1
                                                                                 • TH = shortest TH = min (TH1, TH2,THn )

                                                                                                                                        12
                                                                                                          TSC Americas – IRD Platform – I2C
  Multi Master Mode - Arbitration
   • Two or more masters may generate a START condition at the same time
   • Arbitration is done on SDA while SCL is HIGH - Slaves are not involved

                  Master 2 loses arbitration because DATA2  SDA

DATA1                                             “0”
    0


                                                  “1”

DATA2
      0


                                                  “0”
SDA
    0



 SCL
    0
          START      “1”            “0”           “0”              “1”   “1”                   “0”




  SUMMARY: the master that sends a “1” while the other sends a “0” loses
           the arbitration

                                                                                                             13
                                                                               TSC Americas – IRD Platform – I2C
Test: I2C Protocol Summary
 START         HIGH to LOW transition on SDA while SCL is HIGH
 STOP          LOW to HIGH transition on SDA while SCL is HIGH
 DATA           8-bit word, MSB first (Address, Control, Data)
                  - must be stable when SCL is HIGH .
                  - can change only when SCL is LOW.
                  - number of bytes transmitted is unrestricted .
 ACKNOWLEDGE    - done on each 9 th clock pulse during the HIGH period
                - the transmitter releases the bus - SDA goes HIGH .
                - the receiver pulls DOWN the bus line - SDA goes LOW .
 CLOCK          - Generated by the master (s)
                - Maximum speed: (100 , 400 , 1000 , 3400 kHz) but NO min.
                - A receiver can hold SCL LOW when performing
                  another function (transmitter in a Wait state)
                - A master can slow down the clock for slow devices
 ARBITRATION   - Master can start a transfer only if the bus is free .
               - Several masters can start a transfer at the same time .
               - Arbitration is done on SDA line
               - Master that lost the arbitration must stop sending data


                                                                                             14
                                                               TSC Americas – IRD Platform – I2C
IRD
I²C Functionality




                                                  15
                    TSC Americas – IRD Platform – I2C
PCA9551
8-bit I2C LED Driver
  8 open drain LED drivers (on, off, flashing at a programmable
  rate) with 25 mA driving capability per output
  2 selectable, fully programmable blink rates (frequency and
  duty cycle) between 0.148 Hz and 38 Hz (6.74 seconds and
  0.026 seconds)
  Input/outputs not used as LED drivers can be used as regular
  GPIOs
  Operating power supply voltage range: 2.3 V to 5.5 V
  Internal oscillator requires no external components
  Internal power-on reset
  Active LOW reset input
  Edge rate control on outputs
  Supports hot insertion
  Low standby current
  Package offering:
    – SO16
    – TSSOP16
    – HVQFN16


                                                                                                16
                                                                  TSC Americas – IRD Platform – I2C
  PCA9551                                                               INPUT – Input Register: read back LED
  Device Hardware / Register Definition                                 driver logic state

                         Programmable I2C Addresses                       LSx – LED Selector: selects the
                          8 devices in the same bus                       state of the LED Driver




   5 V tolerant
   I2C bus


                                                                                                   5 V tolerant, 25 mA
                                                                                                   capable open drain
                                                                                                   LED drivers




Device powers up in a known        PSCx - Prescaler register: defines the frequency to be used for the LED
state                              PWMx – Pulse Width Modulation register: defines the duty cycle for the LED
Active low RESET pin                         x = 0 or 1
initializes the device in the
same known state              Internal oscillator – does not require any additional components

                                                                                                                        17
                                                                                          TSC Americas – IRD Platform – I2C
PCA9551
Register definition / Programming
 Registers:
     INPUT: allows reading of the LED driver outputs
     PSC0 & PWM0: define the Blinking or Dimming scheme 0 (8-bit value each)
     PSC1 & PWM1: define the Blinking or Dimming scheme 1 (8-bit value each)
     LS0 (up to LS3): defines the LED driver output state (4 possible states per output)
 A Blinking/Dimming scheme is defined by its period (PSC) and duty cycle (PWM)
 Programming differences                                    256 - PWMx
     Frequency and duty cycles calculation                       256                        LED BLINKERS

     LED output state programming (2 bits per output)          ON               OFF                 ON        OFF
                                                                           PSCx +
          Value     LED DIMMERS LED BLINKERS                                  1
                                                                             40

           00           OFF          ON                            PWMx
                                                                    256                       LED DIMMERS
           01           ON          OFF
           10          Rate 0      Rate 0                         ON            OFF        ON              OFF        ON

            11         Rate 1      Rate 1                            PSCx + 1
                                                                       160             ON =               LED ON
 Auto Increment feature                                                               OFF =              LED OFF

    Allows more than one register to be programmed (or read) with the same command
    Bit 4 in the Control Register (2nd byte - contains the # of the register to be addressed)
          INPUT  PSC0  PWM0  PSC1  PSC2  LS0  LS1  LS2  LS3


                                                                                                                18
                                                                                  TSC Americas – IRD Platform – I2C
SA56004
Remote & Local Temperature Sensor
 Monitors remote and local temperatures
 Accuracy of ±1 °C remote temperature sensing
 11-bit ADC or 0.125 °C resolution
 Temperature range of −40 °C to +125 °C
 Offset registers for the remote sensing accuracy
 Programmable under/over temperature alarms
   – /ALERT and /T_CRIT
 2-wire SMBus, or I2C standard/fast mode compatible
 Supports SMBus ALERT Response and TIMEOUT
 One-shot control for power saving
 Programmable Fault Queue
 Diode fault detection
 8 different device addresses
 Package offerings
   – S08
   – TSSOP8 (MSOP8)
   – HVSON8


                                                                                    19
                                                      TSC Americas – IRD Platform – I2C
SA56004                                                    Command and Configuration

Block Diagram   Local Temp Sensor                          Low and High Limits
                             11-bit S-D ADC




Remote
Temp Sensor



Interrupt
Outputs




                                              I2C-Bus interface



                                                                                                20
                                                                  TSC Americas – IRD Platform – I2C
SA56004
Registers




                                          21
            TSC Americas – IRD Platform – I2C
P82B486
3-channel differential I2C-bus
  3-channel bidirectional differential to single-ended buffer
  Compatible with I2C-bus Standard/Fast-mode and
  SMBus at 400 kHz
  Higher frequencies up to 1 MHz in uni-directional mode
  Single-ended I2C-bus on card side up to 400 pF
  Differential I2C-bus on cable side supporting multi-drop
  bus
  Maximum cable length: 3000 feet (longer at lower
  frequency)
  Maximum number devices: 256
  Supports arbitration and clock stretching across the
  repeater
  I2C-bus operating supply voltage (VCCA) range of 3.0 V to
  5.5 V with single-ended side
  5.5 V tolerant
  Differential I2C-bus operating supply voltage (VCC) range
  of 4.5 V to 5.5 V
  Various Packages Offered
    – SO14
    – TSSOP16


                                                                                              22
                                                                TSC Americas – IRD Platform – I2C
IRD Keypad
Optimized for embedded applications

 Why should I use I2C to enable a keypad?
   – A 16-key keypad requires 8 wires       (4x4)
   – A 64-key keypad requires 16 wires      (8x8)

 Implementation uses 3 wires to interface with the microcontroller
 regardless of keypad size: SDA, SCL and Interrupt
 An I2C GPIO (also called I/O Expander) allows control of the keypad’s
 rows and columns
 Interrupt pin asserted when a key is pressed
   – No need for the microcontroller to poll the I/O Expander
   – Interrupt Service Routine starts when Interrupt is asserted

 Simple decoding scheme
   – Requires only a few I2C Read and Write sequences


                                                                                                 23
                                                                   TSC Americas – IRD Platform – I2C
IRD Keypad
Parallel versus I2C



                                   LEFT:
                        Serial – I2C based Keypad
                                RIGHT:
                             Parallel Keypad




  Advantages for the I2C solution:
   – Less pins used to control the keyboard
   – Less traces to route on both the host board and the keypad
   – Cheaper connector


                                                                                                24
                                                                  TSC Americas – IRD Platform – I2C
Keypad using I²C
           Red          Orange           Green




                                                  Not populated


                 Note: located on the IRD board




                                                                                       25
                                                         TSC Americas – IRD Platform – I2C
PCA9555
16-bit I2C GPIO with Interrupt
  Operating power supply voltage range
  of 2.3 V to 5.5 V
  5 V tolerant I/Os
  Polarity Inversion register
  Active LOW interrupt output
  Low standby current
  Noise filter on SCL/SDA inputs
  No glitch on power-up
  Internal power-on reset
  16 I/O pins which default to 16 inputs
  0 Hz to 400 kHz clock frequency
  ESD protection exceeds 2000 V HBM,
  200 V MM and 1000 V CDM
  Various Packages Offered
    –   DIP24
    –   SO24
    –   SSOP24
    –   TSSOP24
    –   HVQFN24
    –   HVQFN24


                                                                         26
                                           TSC Americas – IRD Platform – I2C
PCA9555 - Port functionality
  Configuration Register                           Output Port Register:
  Allows to configure the I/O as:
  - input when = 1                                 Allows to force an output port to 0 or 1
  - output when = 0                                                                                     Totem Pole
                                                                                                        I/O structure



                                                                                                       Interrupt
                                                                                                       circuitry




                   Polarity Inverter Register
                                                                        Input Port Register
                   Polarity is retained when = 0
                   Polarity is inverted when = 1

                                                                                                                   27
                                                                                     TSC Americas – IRD Platform – I2C
   Keypad Controller
   How the stuff works – Part 1                                        The Keypad is a matrix:
        VCC
                                                                       - Rows
                                                                       - Columns
              OFF
                    0
ROW 0
                                                                       Rows are controlled by a driver
              ON                                                        Write “1” or “0”
                                              (0,1)            (0,0)
                        Key not pressed                                Columns are configured as
        VCC             No connection                                  inputs
              OFF                                                       Read “1” or “0”
                    0
ROW 1
                                                                       At idle:
              ON                              (1,1)            (1,0)
                                                                         – the drivers (row) are at “0”
                                 VCC               VCC
                                                                         – The inputs (column) are at “1”

                                          1                1
                                        COLUMN 1         COLUMN 0




                                                                                                                    28
                                                                                      TSC Americas – IRD Platform – I2C
   Keypad Controller
   How the stuff works - Part 2

        VCC                                                           When a key is pressed
              OFF
                                                                      – The corresponding input
                    0
ROW 0                                                                    (column) goes to “0”
              ON
                                              (0,1)           (0,0)   – The Interrupt line of the
                        Key pressed                                      PCA9555 is asserted
        VCC             Connection made                               – The Keypad decoding
              OFF                                                        sequence starts:
                    0
ROW 1                                                                 1. A Read sequence of the Input
              ON                              (1,1)           (1,0)      port is performed
                                VCC              VCC

                                                                       Column is known (#1)
                                          0               1
                                      COLUMN 1         COLUMN 0




                                                                                                                  29
                                                                                    TSC Americas – IRD Platform – I2C
  Keypad Controller
  How the stuff works – Part 3
              Row Counter = 0                                  Two I2C Write then Read
                 Row Counter = 1
                                                                  sequences are performed to
        VCC
                                                                  recognize the row
              0   0                                                •   The number of Write then
ROW 0                                                                  Read sequences is equal to
                                                                       the number of rows in
                                      (0,1)            (0,0)           thekeypad
                  Key pressed                                            –   1st write (#0)        = 10

        VCC       Connection made                                        –   2nd write (#1)        = 00

                                                                   •   If the associated Read is 11,
              1   0
                                                                       no row has been detected
ROW 1
                                                                   •   If the associated Read is not
                                      (1,1)            (1,0)           11 (one input read bit is now 0)
                                                                       then the row is known
                          VCC              VCC



                                1      0         1     1        Row is known (#1)
                                COLUMN 1         COLUMN 0




                                                                                                           30
                                                                             TSC Americas – IRD Platform – I2C
Decoding applied to a (up to) 64-key Keypad
   Output Port = 0x00
   Input Port = 0xFF




           Key               NO
        pressed?


               YES

    Interrupt asserted
    Input Port is read
     (value is ≠ 0xFF)
    Column is known
       Counter = 0

                                                                                              Increment Counter (+1)

                                             Write to Output Port
                                  If Counter = 0       Output Port = 0xFE
        Counter >            NO   If Counter = 1       Output Port =0xFC
           7?                      If Counter = 2       Output Port =0xF8
                                   If Counter = 3       Output Port =0xF0                         Input Port ≠    NO
                                                                            Read Input Port
                                   If Counter = 4       Output Port =0xE0                            0xFF?
               YES                 If Counter = 5       Output Port =0xC0
                                   If Counter = 6       Output Port =0x80
                                                                                                         YES
                                   If Counter = 7       Output Port =0x00

          Key                NO                                                                  Row is known
       Released?                                                                               Row value = Counter


               YES

    Read Input Port to
  clear the last Interrupt




                                                                                                                                           31
                                                                                                             TSC Americas – IRD Platform – I2C
Keypad
Mapping with the PCA9555                          P1.5   P1.4       P1.3   P1.2       P1.1      P1.0
                                                   5      4          3      2          1         0


                               P0.5   5


                               P0.4   4


                               P0.3   3

                              P0.2    2


                              P0.1    1


                              P0.1    0

                              GND

                              GND

                              P0 is the input port        (Read)
                              P1 is the output port       (Write)


 P0.6 controls the Keypad backlight          P0.7 controls the Green status LED
 P1.6 controls the Yellow status LED         P1.7 controls the Red status LED

                                                                                                                32
                                                                                  TSC Americas – IRD Platform – I2C
Hands-On
Become familiar with the keypad and the keypad scanning routine

   Exercise 1: Fill the blanks ……
    1. Try all the keys in the keypads and write down the keys that are not displayed in the

       VFD

    2. Map the missing keys in the Keypad_Map() function so that the entire keypad is now

       displayed in the VFD. Function to complete is in bsp_keypad.c file




   Exercise 2: Create Green_LED_On_Off () and Modify Display_Key() to:
    1. Switch ON the Green LED in the keypad when F4 is pressed once

    2. Switch OFF the Green LED in the keypad when F4 is pressed again
                                           These steps are covered in detail in the
                                                                upcoming slides


                                                                                                          33
                                                                            TSC Americas – IRD Platform – I2C
Exercise 1
Complete the keypad decoding – See bsp_keyboard.c and keypad.h
CPU_INT08U Keypad_Map(void)
{
                                                                        P1.5   P1.4       P1.3     P1.2       P1.1      P1.0
    CPU_INT08U lKey = 0;                                                 5      4          3        2          1         0
    if (Column_Value == 5 {
      if (Row_Value == 0)    lKey = KEY_F4;
      else if (Row_Value == 1) lKey = KEY_ARW_UP;
      else if (Row_Value == 2) lKey = KEY_PLUS;      P0.5   5
      else if (Row_Value == 3) lKey = KEY_F3;
      else if (Row_Value == 4) lKey = KEY_F2;
}
    else if (Column_Value == 4) {
      if (Row_Value == 0)     lKey = KEY_MENU;
                                                     P0.4   4
      else if (Row_Value == 1) lKey = KEY_ARW_DN;
      else if (Row_Value == 3) lKey = KEY_ARW_RT;
      else if (Row_Value == 4) lKey = KEY_OK;
      else if (Row_Value == 5) lKey = KEY_ARW_LT;   P0.3    3
    }
    else if (Column_Value == 3) {
      if (Row_Value == 0)     lKey = KEY_ERROR;
      else if (Row_Value == 1) lKey = KEY_3;        P0.2    2
      else if (Row_Value == 2) lKey = KEY_2;
      else if (Row_Value == 3) lKey = KEY_1;
      else if (Row_Value == 5) lKey = KEY_SEND;
    }                                               P0.1    1
    else if (Column_Value == 2) {
      if (Row_Value == 0)     lKey = KEY_ERROR;
      else if (Row_Value == 1) lKey = KEY_ERROR;
      else if (Row_Value == 2) lKey = KEY_7;
      else if (Row_Value == 3) lKey = KEY_6;        P0.1    0
      else if (Row_Value == 4) lKey = KEY_5;
      else if (Row_Value == 5) lKey = KEY_4;
    }
    else if (Column_Value == 1) {                   GND
      if (Row_Value == 0)     lKey = KEY_ERROR;
       else if (Row_Value == 2) lKey = KEY_0;
      else if (Row_Value == 4) lKey = KEY_9;        GND
      else if (Row_Value == 5) lKey = KEY_8;
    }
    else if (Column_Value == 0)
    {                                               P0 is the input port        (Read)      Coded as “columns”
      lKey = KEY_END;                               P1 is the output port       (Write)     Coded as “rows”
    }

    return lKey;                                    Note: Rows and Columns naming convention is the same as in the
}
                                                    keyboard mode of operation (previous slides)




                                                                                                                           34
                                                                                             TSC Americas – IRD Platform – I2C
Exercise 2
Turn on the Green LED (Port 0, bit 7) in the keypad when you press F4

  Use Green_LED_On_Off () in bsp_keyboard.c (end of file)

  Use the following to determine the value to be written to the PCA9555
                                                                                       Green
   – PROGRAM_KEYPAD_GREEN_LED_ON                                                        LED
   – PROGRAM_KEYPAD_GREEN_LED_OFF

  They are used as parameters to be sent to Keypad_Write()
   – Hint: See how Keypad_Write() is used in

      Keypad_Init() (see bsp_keyboard.c file)

  Modify Display_Key() in app_keyboard.c in order

  to call Green_LED_On_Off()



                                                                                               35
                                                                 TSC Americas – IRD Platform – I2C
Solution
Exercise 1

 CPU_INT08U Keypad_Map(void)                      else if (Column_Value == 2)
 {                                                 {
                                                     if (Row_Value == 0)    lKey = KEY_ERROR;
  CPU_INT08U lKey = 0;                               else if (Row_Value == 1) lKey = KEY_ERROR;
                                                     else if (Row_Value == 2) lKey = KEY_7;
  if (Column_Value == 5)                             else if (Row_Value == 3) lKey = KEY_6;
  {                                                  else if (Row_Value == 4) lKey = KEY_5;
    if (Row_Value == 0)    lKey = KEY_F4;            else if (Row_Value == 5) lKey = KEY_4;
    else if (Row_Value == 1) lKey = KEY_ARW_UP;    }
    else if (Row_Value == 2) lKey = KEY_PLUS;      else if (Column_Value == 1)
    else if (Row_Value == 3) lKey = KEY_F3;        {
    else if (Row_Value == 4) lKey = KEY_F2;          if (Row_Value == 0)    lKey = KEY_ERROR;
    else if (Row_Value == 5) lKey = KEY_F1;          else if (Row_Value == 1) lKey = KEY_POUND;
  }                                                  else if (Row_Value == 2) lKey = KEY_0;
  else if (Column_Value == 4)                        else if (Row_Value == 3) lKey = KEY_ASTERISK;
  {                                                  else if (Row_Value == 4) lKey = KEY_9;
    if (Row_Value == 0)    lKey = KEY_MENU;          else if (Row_Value == 5) lKey = KEY_8;
    else if (Row_Value == 1) lKey = KEY_ARW_DN;    }
    else if (Row_Value == 2) lKey = KEY_MINUS;     else if (Column_Value == 0)
    else if (Row_Value == 3) lKey = KEY_ARW_RT;    {
    else if (Row_Value == 4) lKey = KEY_OK;          lKey = KEY_END;
    else if (Row_Value == 5) lKey = KEY_ARW_LT;    }
  }
  else if (Column_Value == 3)                         return lKey;
  {                                               }
    if (Row_Value == 0)    lKey = KEY_ERROR;
    else if (Row_Value == 1) lKey = KEY_3;
    else if (Row_Value == 2) lKey = KEY_2;
    else if (Row_Value == 3) lKey = KEY_1;
    else if (Row_Value == 4) lKey = KEY_CLEAR;
    else if (Row_Value == 5) lKey = KEY_SEND;
  }




                                                                                                                    36
                                                                                      TSC Americas – IRD Platform – I2C
Solution     Green_LED_On_Off() function in bsp_keyboard.c file:
             #define PROGRAM_KEYPAD_GREEN_LED_ON               0x7F
Exercise 2   #define PROGRAM_KEYPAD_GREEN_LED_OFF              0xFF
             CPU_INT08U F4_Flag = 0;


             void Green_LED_On_Off (void)
             {
                 switch (F4_Flag)
                 {
                     case 0: F4_Flag = 1;
                             Keypad_Write(0x02,PROGRAM_KEYPAD_GREEN_LED_ON);
                             break;
                     case 1: F4_Flag = 0;
                              Keypad_Write(0x02,PROGRAM_KEYPAD_GREEN_LED_OFF);
                             break;
                 }
             }


             Display_Key() function in app_keyboard.c file:
             .
             .
             .
             case KEY_F3:
                DispStr(3,0,"F3");
                break;
               case KEY_F4:
                DispStr(3,0,"F4");
                Green_LED_On_Off(); // Switch On/Off Green LED in the Keypad - Keypad Hands-On ; Exercise 2
                break;
               case KEY_PLUS:
                DispStr(3,0,"+");
                break;
             .
             .




                                                                                                                                    37
                                                                                                      TSC Americas – IRD Platform – I2C
A Quick look at the Keypad Controller Code (1)
  Keypad Controller code is located in the bsp_keyboard.c file
  PCA9555 initialization (input / output configuration) is done in the
  Keypad_Init() function
  #define P0_6_BACKLIGHT_OUT_REG        0xBF           // P0[6] configured as output
  #define P0_7_LED_OUT_REG              0x7F           // P0[7] configured as output
  #define P1_KPAD_ROW_OUT_REG           0xC0           // Row configured as output
  #define P1_7_6_LED_OUT_REG            0x3F           // P1[7:6] configured as output

  void Keypad_Init(void)
  {
    Keypad_Write(0x06, P0_7_LED_OUT_REG & P0_6_BACKLIGHT_OUT_REG); // Program output port 0
    Keypad_Write(0x07, P1_7_6_LED_OUT_REG & P1_KPAD_ROW_OUT_REG); // Program output port 1
    Keypad_Write(0x03,0xC0);                   // Program Port1 - LEDs off and Kpad Column = 0
  }


  The Keypad_Write(Register_Pointer, Data) function allows to write to the
  PCA9555
  The Keypad_Read() function allows to read data from the PCA9555’s
  Input Port0 Register. The read data value is returned.


                                                                                                                               38
                                                                                                 TSC Americas – IRD Platform – I2C
A Quick look at the Keypad Controller Code (2)
The Decode_Column() function                               The Decode_Row() function allows to
allows to find the Column                                  find the Row coordinates
coordinates                                                void Decode_Row(void)
                                                           {
    void Decode_Column(void)                                 Int8U Keypad_Data_Read;
    {                                                        Int8U Keypad_Data_Read_Masked;
         switch (Keypad_Data_Read | P1_KPAD_COLUMN_MASK)     do
        {                                                    {
           case 0xFE: Column_Value = 0;                        if (Row_Counter == 0) Keypad_Write(0x03,0xFE);
                       break;                                  if (Row_Counter == 1) Keypad_Write(0x03,0xFC)
           case 0xFD: Column_Value = 1;                        if (Row_Counter == 2) Keypad_Write(0x03,0xF8);
                       break;                                  if (Row_Counter == 3) Keypad_Write(0x03,0xF0);
           case 0xFB: Column_Value = 2;                        if (Row_Counter == 4) Keypad_Write(0x03,0xE0);
                       break;                                  if (Row_Counter == 5) Keypad_Write(0x03,0xC0);
           case 0xF7: Column_Value = 3;
                      break;                                Keypad_Data_Read = Keypad_Read();
           case 0xEF: Column_Value = 4;                     Keypad_Data_Read_Masked = Keypad_Data_Read
                      break;                               P1_KPAD_COLUMN_MASK;
           case 0xDF: Column_Value = 5;                     if (Keypad_Data_Read_Masked != 0xFF)
                      break;                                {
           default:   break;                                  if (Row_Found == 0)
      }                                                       {
}                                                               Row_Value = Row_Counter;
                                                                Row_Found = 1;
Note: reading of the Input register is                      }
                                                              }


done in app_keyboard.c                                      Row_Counter+=1;


(CPU_INT08U KeypadCheck ( void)                            }
                                                               } while (Row_Counter <= KPAD_NB_ROW-1);

function)

                                                                                                                                     39
                                                                                                       TSC Americas – IRD Platform – I2C
A Quick look at the Keypad Controller Code (3)
  The Keypad_Map() function allows to determine which key has been
  pressed. The function returns the name of the key.
  See Exercise 1

  The Keypad_Decoder() is the main function executing the functions
  previously described
   void Keypad_Decoder (void)
   {
       Decode_Column();
       Decode_Row();
       Keypad_Map();
   }




  The Display_Key() function in the app_keyboard.c file allows the pressed
  key to be displayed in the VFD


                                                                                       40
                                                         TSC Americas – IRD Platform – I2C

								
To top