Firmware for MAXREFES1265
Dependencies: max32625pico SerialInterface maxim-dev USBDevice
MAXREFDES1265 Numeric keypad interface using MAX7360 and MAX32625PICO
Description: MAX7360 is an I2C interfaced key switch controller when integrated with a microcontroller it can be used to control the numeric keypad
Operation: This code was developed in a such a way that initially all the registers in MAX7360 gets initialized and based upon the key press the data gets displayed on Serial monitor
main.cpp@1:6dcb933b366d, 2020-05-05 (annotated)
- Committer:
- brianh
- Date:
- Tue May 05 17:47:25 2020 +0000
- Revision:
- 1:6dcb933b366d
- Parent:
- 0:4a433af35131
Changed from Blinky readme to project readme.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
venkik | 0:4a433af35131 | 1 | /******************************************************************************* |
venkik | 0:4a433af35131 | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
venkik | 0:4a433af35131 | 3 | * |
venkik | 0:4a433af35131 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
venkik | 0:4a433af35131 | 5 | * copy of this software and associated documentation files (the "Software"), |
venkik | 0:4a433af35131 | 6 | * to deal in the Software without restriction, including without limitation |
venkik | 0:4a433af35131 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
venkik | 0:4a433af35131 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
venkik | 0:4a433af35131 | 9 | * Software is furnished to do so, subject to the following conditions: |
venkik | 0:4a433af35131 | 10 | * |
venkik | 0:4a433af35131 | 11 | * The above copyright notice and this permission notice shall be included |
venkik | 0:4a433af35131 | 12 | * in all copies or substantial portions of the Software. |
venkik | 0:4a433af35131 | 13 | * |
venkik | 0:4a433af35131 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
venkik | 0:4a433af35131 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
venkik | 0:4a433af35131 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
venkik | 0:4a433af35131 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
venkik | 0:4a433af35131 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
venkik | 0:4a433af35131 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
venkik | 0:4a433af35131 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
venkik | 0:4a433af35131 | 21 | * |
venkik | 0:4a433af35131 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
venkik | 0:4a433af35131 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
venkik | 0:4a433af35131 | 24 | * Products, Inc. Branding Policy. |
venkik | 0:4a433af35131 | 25 | * |
venkik | 0:4a433af35131 | 26 | * The mere transfer of this software does not imply any licenses |
venkik | 0:4a433af35131 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
venkik | 0:4a433af35131 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
venkik | 0:4a433af35131 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
venkik | 0:4a433af35131 | 30 | * ownership rights. |
venkik | 0:4a433af35131 | 31 | *******************************************************************************/ |
venkik | 0:4a433af35131 | 32 | //============================================================================== |
venkik | 0:4a433af35131 | 33 | //This code is only suitable for single switch press not simultaneous switch press |
venkik | 0:4a433af35131 | 34 | //The following code needs maxim-dev library to run. The complete package is available in the GITHUB |
venkik | 0:4a433af35131 | 35 | //============================================================================== |
venkik | 0:4a433af35131 | 36 | //Header files |
venkik | 0:4a433af35131 | 37 | #include "mbed.h" |
venkik | 0:4a433af35131 | 38 | #include "USBSerial.h" |
venkik | 0:4a433af35131 | 39 | #include "max32625pico.h" |
venkik | 0:4a433af35131 | 40 | #include "SerialInterface.h" |
venkik | 0:4a433af35131 | 41 | |
venkik | 0:4a433af35131 | 42 | |
venkik | 0:4a433af35131 | 43 | const int Slave_address = 0x70; // MAX7360 I2C slave address |
venkik | 0:4a433af35131 | 44 | const int max_key = 63; |
venkik | 0:4a433af35131 | 45 | |
venkik | 0:4a433af35131 | 46 | // Virtual serial port over USB |
venkik | 0:4a433af35131 | 47 | USBSerial microUSB(0x0B6A, 0x4360); |
venkik | 0:4a433af35131 | 48 | |
venkik | 0:4a433af35131 | 49 | DigitalIn nINTK(P4_5); // Key switch interrupt configures as GPIO, refer to page 11 of DS for more info |
venkik | 0:4a433af35131 | 50 | |
venkik | 0:4a433af35131 | 51 | //The following line of code is optional and please uncomment if you are using rotary encoder |
venkik | 0:4a433af35131 | 52 | //DigitalIn nINTI(P4_4); // Interrupt for rotary switch configuration, refer to page 14 for more info |
venkik | 0:4a433af35131 | 53 | |
venkik | 0:4a433af35131 | 54 | //The following line of code sets all the GPIO to 1.8 volts |
venkik | 0:4a433af35131 | 55 | MAX32625PICO pico(MAX32625PICO::IOH_DIP_IN, MAX32625PICO::VIO_IOH, MAX32625PICO::VIO_1V8); |
venkik | 0:4a433af35131 | 56 | |
venkik | 0:4a433af35131 | 57 | // Serial Interfaces |
venkik | 0:4a433af35131 | 58 | I2C i2c(P1_6, P1_7); |
venkik | 0:4a433af35131 | 59 | |
venkik | 0:4a433af35131 | 60 | |
venkik | 0:4a433af35131 | 61 | |
venkik | 0:4a433af35131 | 62 | int main() |
venkik | 0:4a433af35131 | 63 | { |
venkik | 0:4a433af35131 | 64 | |
venkik | 0:4a433af35131 | 65 | |
venkik | 0:4a433af35131 | 66 | //--------Register configuration for the MAX7360-------------------------------- |
venkik | 0:4a433af35131 | 67 | //Please refer to page 10 and table 8 of the data sheet |
venkik | 0:4a433af35131 | 68 | |
venkik | 0:4a433af35131 | 69 | //Writing the configuration register (0x01) of MAX7360. |
venkik | 0:4a433af35131 | 70 | |
venkik | 0:4a433af35131 | 71 | |
venkik | 0:4a433af35131 | 72 | char Datawrite_config[2]; |
venkik | 0:4a433af35131 | 73 | Datawrite_config[0] = 0x01; //Address of the register |
venkik | 0:4a433af35131 | 74 | Datawrite_config[1] = 0x20; //Configuring the register for Interrupt by making D5 to 1 and all the other bits to 0 |
venkik | 0:4a433af35131 | 75 | i2c.write( Slave_address, Datawrite_config, 2 ); |
venkik | 0:4a433af35131 | 76 | |
venkik | 0:4a433af35131 | 77 | //Writing the Key switch interrupt register (0x03) MAX7360. |
venkik | 0:4a433af35131 | 78 | //Please refer to table 10 of the data sheet |
venkik | 0:4a433af35131 | 79 | //The interrupt register contains information related to the |
venkik | 0:4a433af35131 | 80 | //settings of the interrupt request function, as well as the |
venkik | 0:4a433af35131 | 81 | //status of the INTK output, which can also be configured |
venkik | 0:4a433af35131 | 82 | //as a GPIO |
venkik | 0:4a433af35131 | 83 | char Datawrite_Key_Switch_Interrupt[2]; |
venkik | 0:4a433af35131 | 84 | Datawrite_Key_Switch_Interrupt[0] = 0x03; //Address of the register |
venkik | 0:4a433af35131 | 85 | Datawrite_Key_Switch_Interrupt[1] = 0x08; //Configuring the TIME-BASED INTK bits to get 8 debounce cycles |
venkik | 0:4a433af35131 | 86 | i2c.write( Slave_address, Datawrite_Key_Switch_Interrupt, 2 ); |
venkik | 0:4a433af35131 | 87 | |
venkik | 0:4a433af35131 | 88 | |
venkik | 0:4a433af35131 | 89 | //Writing the auto sleep register (0x06)MAX7360 Autosleep Register no autosleep |
venkik | 0:4a433af35131 | 90 | char Autosleep[2]; |
venkik | 0:4a433af35131 | 91 | Autosleep[0] = 0x06; //Address of the register |
venkik | 0:4a433af35131 | 92 | Autosleep[1] = 0x00; //AUTOSHUTDOWN TIME to no autosleep, refer to page 25 of DS |
venkik | 0:4a433af35131 | 93 | i2c.write( Slave_address, Autosleep, 2 ); |
venkik | 0:4a433af35131 | 94 | |
venkik | 0:4a433af35131 | 95 | |
venkik | 0:4a433af35131 | 96 | //Writing the GPIO Global Configuration (0x40) |
venkik | 0:4a433af35131 | 97 | //Enable rotary encoder and normal GPIO operation |
venkik | 0:4a433af35131 | 98 | char GlobalConfig[2]; |
venkik | 0:4a433af35131 | 99 | GlobalConfig[0] = 0x40; //Address of the register |
venkik | 0:4a433af35131 | 100 | GlobalConfig[1] = 0x90; //Enabling the I2C timeout interrupt and rotary switch by setting D7 and D5 to 1 and all others to zero |
venkik | 0:4a433af35131 | 101 | i2c.write( Slave_address, GlobalConfig, 2 ); |
venkik | 0:4a433af35131 | 102 | |
venkik | 0:4a433af35131 | 103 | //============================================================================== |
venkik | 0:4a433af35131 | 104 | //Uncomment below if you would like ot use rotary encoder |
venkik | 0:4a433af35131 | 105 | //============================================================================== |
venkik | 0:4a433af35131 | 106 | //Writing GPIO Control Register |
venkik | 0:4a433af35131 | 107 | // char GPIOControl[2]; |
venkik | 0:4a433af35131 | 108 | // GPIOControl[0] = 0x41; //Address |
venkik | 0:4a433af35131 | 109 | // GPIOControl[1] = 0x3F; //Registrer configuration, All GPIOs configured as output, except ports 6 and 7, because they are connected to the rotary encoder |
venkik | 0:4a433af35131 | 110 | // i2c.write( Slave_address, GPIOControl, 2 ); |
venkik | 0:4a433af35131 | 111 | //Writing the Rotatory switch configuration (0x46). Please refer to table 20 of the data sheet |
venkik | 0:4a433af35131 | 112 | // char Datawrite_Rotatory_Switch_configuration[2]; |
venkik | 0:4a433af35131 | 113 | //Rotary Switch Configuration Register nINTI asserted 25ms after first debounced event, no debounce cycle time |
venkik | 0:4a433af35131 | 114 | // Datawrite_Rotatory_Switch_configuration[0] = 0x46; |
venkik | 0:4a433af35131 | 115 | // Datawrite_Rotatory_Switch_configuration[1] = 0x90; // Rotary Switch Configuration Register nINTI asserted 25ms after first debounced event, no debounce cycle time |
venkik | 0:4a433af35131 | 116 | //Datawrite_Rotatory_Switch_configuration[1] = 0x11; |
venkik | 0:4a433af35131 | 117 | // i2c.write( Slave_address, Datawrite_Rotatory_Switch_configuration, 2 ); |
venkik | 0:4a433af35131 | 118 | |
venkik | 0:4a433af35131 | 119 | /* |
venkik | 0:4a433af35131 | 120 | // Writing PORT6 Configuration Register mask interrupt (0x5E) |
venkik | 0:4a433af35131 | 121 | char Port6[2]; |
venkik | 0:4a433af35131 | 122 | Port6[0] = 0x5E; // Address |
venkik | 0:4a433af35131 | 123 | Port6[1] = 0x80;// masking the interrupt by enabling the D7 to 1 refer to page 30 of DS |
venkik | 0:4a433af35131 | 124 | i2c.write( Slave_address, Port6, 2 ); |
venkik | 0:4a433af35131 | 125 | |
venkik | 0:4a433af35131 | 126 | // Writing PORT7 Configuration Register mask interrupt (0x5F) |
venkik | 0:4a433af35131 | 127 | char Port7[2]; |
venkik | 0:4a433af35131 | 128 | Port7[0] = 0x5F; //Address |
venkik | 0:4a433af35131 | 129 | Port7[1] = 0x80; // masking of the interrupt by making D7 to 1 refer to page 30 of DS |
venkik | 0:4a433af35131 | 130 | i2c.write( Slave_address, Port7, 2 ); |
venkik | 0:4a433af35131 | 131 | */ |
venkik | 0:4a433af35131 | 132 | //----------------------------------------------------------------------------- |
venkik | 0:4a433af35131 | 133 | //Default register values |
venkik | 0:4a433af35131 | 134 | //----------------------------------------------------------------------------- |
venkik | 0:4a433af35131 | 135 | //writeMAX7360(0x02,0xFF);// Debounce Register only column 0 enabled, debounce set to 40ms |
venkik | 0:4a433af35131 | 136 | // writeMAX7360(0x04,0xFE); // Ports Register |
venkik | 0:4a433af35131 | 137 | // writeMAX7360(0x05,0x00); // Autorepeat Register |
venkik | 0:4a433af35131 | 138 | // writeMAX7360(0x42,0x00); // GPIO Debounce Configuration Register |
venkik | 0:4a433af35131 | 139 | // writeMAX7360(0x43,0xC0); // GPIO Constant-Current Setting Register |
venkik | 0:4a433af35131 | 140 | // writeMAX7360(0x44,0x00); // GPIO Output Mode Register |
venkik | 0:4a433af35131 | 141 | // writeMAX7360(0x45,0x00); // Common PWM Register |
venkik | 0:4a433af35131 | 142 | |
venkik | 0:4a433af35131 | 143 | //------------------End of Register configuration for MAX7360-----------------// |
venkik | 0:4a433af35131 | 144 | |
venkik | 0:4a433af35131 | 145 | |
venkik | 0:4a433af35131 | 146 | while(1) { |
venkik | 0:4a433af35131 | 147 | |
venkik | 0:4a433af35131 | 148 | |
venkik | 0:4a433af35131 | 149 | |
venkik | 0:4a433af35131 | 150 | //Reading the Key FIFO register (0x00) from MAX7360. |
venkik | 0:4a433af35131 | 151 | //Please refer to page 10 and table 7 of the data sheet |
venkik | 0:4a433af35131 | 152 | char KeyFIFOData; |
venkik | 0:4a433af35131 | 153 | char l = 0x00; |
venkik | 0:4a433af35131 | 154 | i2c.write( Slave_address, &l, 1 ); |
venkik | 0:4a433af35131 | 155 | i2c.read( Slave_address, &KeyFIFOData, 1 ); |
venkik | 0:4a433af35131 | 156 | |
venkik | 0:4a433af35131 | 157 | |
venkik | 0:4a433af35131 | 158 | if(KeyFIFOData!= max_key) { |
venkik | 0:4a433af35131 | 159 | microUSB.printf("KeyFIFOData = %d \n\r", KeyFIFOData); |
venkik | 0:4a433af35131 | 160 | } |
venkik | 0:4a433af35131 | 161 | |
venkik | 0:4a433af35131 | 162 | // wait_ms(50); This may be necessary for console printing |
venkik | 0:4a433af35131 | 163 | |
venkik | 0:4a433af35131 | 164 | //============================================================================== |
venkik | 0:4a433af35131 | 165 | //Uncomment the code below for rotary encoder |
venkik | 0:4a433af35131 | 166 | //============================================================================== |
venkik | 0:4a433af35131 | 167 | ////Reading the Rotatory switch count register (0x4A). Please refer to page 12 and table 23 of the data sheet |
venkik | 0:4a433af35131 | 168 | // |
venkik | 0:4a433af35131 | 169 | // char RotaryData; |
venkik | 0:4a433af35131 | 170 | // char m = 0x4A; |
venkik | 0:4a433af35131 | 171 | // if(!nINTI) { |
venkik | 0:4a433af35131 | 172 | // i2c.write( Slave_address, &m, 1 ); |
venkik | 0:4a433af35131 | 173 | // i2c.read( Slave_address, &RotaryData, 1 ); |
venkik | 0:4a433af35131 | 174 | // |
venkik | 0:4a433af35131 | 175 | // if(RotaryData!= 0) { |
venkik | 0:4a433af35131 | 176 | // |
venkik | 0:4a433af35131 | 177 | // microUSB.printf("RotaryData = %x \r\n", RotaryData); |
venkik | 0:4a433af35131 | 178 | // } |
venkik | 0:4a433af35131 | 179 | // |
venkik | 0:4a433af35131 | 180 | // // wait_ms(100); This may be necessary for console printing |
venkik | 0:4a433af35131 | 181 | // |
venkik | 0:4a433af35131 | 182 | // } |
venkik | 0:4a433af35131 | 183 | |
venkik | 0:4a433af35131 | 184 | } |
venkik | 0:4a433af35131 | 185 | } |
venkik | 0:4a433af35131 | 186 | |
venkik | 0:4a433af35131 | 187 | |
venkik | 0:4a433af35131 | 188 | |
venkik | 0:4a433af35131 | 189 | |
venkik | 0:4a433af35131 | 190 | |
venkik | 0:4a433af35131 | 191 | |
venkik | 0:4a433af35131 | 192 | |
venkik | 0:4a433af35131 | 193 | |
venkik | 0:4a433af35131 | 194 |