Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| chipkit_shield_basic_io_shield:refmanual [2015/05/27 22:35] – [Rference Manula] Martha | chipkit_shield_basic_io_shield:refmanual [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| - | ====Overview==== | + | ===== Overview |
| The chipKIT Basic I/O Shield is an input/ | The chipKIT Basic I/O Shield is an input/ | ||
| Line 18: | Line 18: | ||
| The Basic I/O Shield has the same form factor as the Uno32 board, but is also useable with the Max32 board. | The Basic I/O Shield has the same form factor as the Uno32 board, but is also useable with the Max32 board. | ||
| - | {{ : | + | {{: |
| Line 34: | Line 34: | ||
| + | ---- | ||
| - | + | ===== 1. chipKIT Basic I/O Shield Hardware Overview ===== | |
| - | + | ||
| - | =====chipKIT Basic I/O Shield Hardware Overview===== | + | |
| The Basic I/O Shield has the following hardware features: | The Basic I/O Shield has the following hardware features: | ||
| Line 44: | Line 43: | ||
| - | **1. Pushbuttons** | + | **1. Pushbuttons:** |
| Four pushbuttons provide discrete momentary-contact digital inputs. These can be accessed using the digitalRead function. | Four pushbuttons provide discrete momentary-contact digital inputs. These can be accessed using the digitalRead function. | ||
| - | + | **2. Slide Switches:** | |
| - | **2. Slide Switches** | + | |
| Four slide switches provide discrete digital inputs. These can be accessed using the digitalRead function. | Four slide switches provide discrete digital inputs. These can be accessed using the digitalRead function. | ||
| - | + | **3. J2: Shield Power Connector:** | |
| - | **3. J2: Shield Power Connector** | + | |
| This connector receives power from the chipKIT microcontroller board. | This connector receives power from the chipKIT microcontroller board. | ||
| - | + | **4. J3: Analog Signal Connector:** | |
| - | **4. J3: Analog Signal Connector** | + | |
| Pin 1 (analog signal A0) is connected to a potentiometer. Pins 5 and 6 (labeled A4 and A5) provide access to the I2C signals SDA and SCL for the I2C bus. The I2C bus is used to access the temperature sensor and the EEPROM and for the I2C daisy chain connector. | Pin 1 (analog signal A0) is connected to a potentiometer. Pins 5 and 6 (labeled A4 and A5) provide access to the I2C signals SDA and SCL for the I2C bus. The I2C bus is used to access the temperature sensor and the EEPROM and for the I2C daisy chain connector. | ||
| Note: On the Uno32 and uC32 boards, you need to set jumpers JP6 & JP7 to the correct position to access the I2C signals on that board. On the Max32 board, you need to use jumper wires to bring the I2C signals onto the board, because the connector that provides the I2C bus on the Max32 board doesn’t contact the Basic I/O Shield. | Note: On the Uno32 and uC32 boards, you need to set jumpers JP6 & JP7 to the correct position to access the I2C signals on that board. On the Max32 board, you need to use jumper wires to bring the I2C signals onto the board, because the connector that provides the I2C bus on the Max32 board doesn’t contact the Basic I/O Shield. | ||
| - | + | **5. Discrete LEDs:** | |
| - | **5. Discrete LEDs** | + | |
| The eight LEDs provide discrete digital outputs. These can be accessed individually using the digitalWrite function. The LEDs are connected to the low eight bits of microcontroller PORTE and all eight can be written at the same time by writing to PORTE. | The eight LEDs provide discrete digital outputs. These can be accessed individually using the digitalWrite function. The LEDs are connected to the low eight bits of microcontroller PORTE and all eight can be written at the same time by writing to PORTE. | ||
| - | + | **6. IC2: Temperature Sensor:** | |
| - | **6. IC2: Temperature Sensor** | + | |
| This is a Microchip TCN75A digital temperature sensor. It is accessed via the I2C bus. | This is a Microchip TCN75A digital temperature sensor. It is accessed via the I2C bus. | ||
| - | + | **7. JP2 & JP3: I2C Pull-up Resistor Enable Jumpers:** | |
| - | **7. JP2 & JP3: I2C Pull-up Resistor Enable Jumpers** | + | |
| These jumpers are used to enable or disable the I2C pull-up resistors on the I2C bus. Installing the shorting blocks enables the resistors. Removing the shorting blocks disables the resistors. | These jumpers are used to enable or disable the I2C pull-up resistors on the I2C bus. Installing the shorting blocks enables the resistors. Removing the shorting blocks disables the resistors. | ||
| - | + | **8. J11: I2C Daisy Chain Connector:** | |
| - | **8. J11: I2C Daisy Chain Connector** | + | |
| This is a 2x4 pin header connector that provides access to the I2C signals SDA and SCL as well as power from the 3.3V power bus and ground. The connector can be used to extend the I2C bus to another board and to power an external I2C device. Digilent has cables and a selection of I2C peripheral modules that can be connected to this shield. | This is a 2x4 pin header connector that provides access to the I2C signals SDA and SCL as well as power from the 3.3V power bus and ground. The connector can be used to extend the I2C bus to another board and to power an external I2C device. Digilent has cables and a selection of I2C peripheral modules that can be connected to this shield. | ||
| - | + | **9. Potentiometer:** | |
| - | **9. Potentiometer** | + | |
| This is a 10K-ohm potentiometer connected across VCC3V3 and ground. It provides an analog input voltage to analog input A0. | This is a 10K-ohm potentiometer connected across VCC3V3 and ground. It provides an analog input voltage to analog input A0. | ||
| - | + | **10. J1 & J2: Digital Signal Connectors:** | |
| - | **10. J1 & J2: Digital Signal Connectors** | + | |
| These connectors bring digital signals from the chipKIT microcontroller board to the Basic I/O shield. | These connectors bring digital signals from the chipKIT microcontroller board to the Basic I/O shield. | ||
| - | + | **11. Organic LED Graphic Display:** | |
| - | **11. Organic LED Graphic Display** | + | |
| This is a 128x32 pixel monochrome OLED graphic display panel is accessed using the SPI interface. | This is a 128x32 pixel monochrome OLED graphic display panel is accessed using the SPI interface. | ||
| - | + | **12. J9 & J10: Digital I/O Signal Connectors:** | |
| - | **12. J9 & J10: Digital I/O Signal Connectors** | + | |
| These are screw terminal connectors that provide access to digital I/O signals 3, 5, 6, and 9. These are four of the PWM signals from the chipKIT microcontroller board. | These are screw terminal connectors that provide access to digital I/O signals 3, 5, 6, and 9. These are four of the PWM signals from the chipKIT microcontroller board. | ||
| - | + | **13. J6: Open Drain FET Power Connector:** | |
| - | **13. J6: Open Drain FET Power Connector** | + | |
| This provides access to the power connections for the open drain FETs. | This provides access to the power connections for the open drain FETs. | ||
| - | + | **14. | |
| - | **14. J7 & J8: Open Drain FET Output** | + | |
| These provide access to the outputs of the open drain FETs. | These provide access to the outputs of the open drain FETs. | ||
| + | ---- | ||
| - | ===== chipKIT Basic I/O Shield Hardware Description ===== | + | ===== 2. chipKIT Basic I/O Shield Hardware Description ===== |
| - | + | ||
| - | + | ||
| - | + | ||
| - | ====Introduction==== | + | |
| The following is a description of the Basic I/O Shield and how to use it. See Appendix A for pin definitions and Appendix B for sample code to use the OLED graphic display. | The following is a description of the Basic I/O Shield and how to use it. See Appendix A for pin definitions and Appendix B for sample code to use the OLED graphic display. | ||
| - | ====OLED Graphic Display==== | + | ==== 2.1 OLED Graphic Display==== |
| The Basic I/O Shield provides a 128x32 pixel organic LED (OLED) graphic display panel, the WiseChip/ | The Basic I/O Shield provides a 128x32 pixel organic LED (OLED) graphic display panel, the WiseChip/ | ||
| Line 120: | Line 103: | ||
| ===Power on sequence: | ===Power on sequence: | ||
| - | 1. Apply power to VDD. | + | - Apply power to VDD. |
| - | 2. Send Display Off command. | + | |
| - | 3. Initialize display to desired operating mode. | + | |
| - | 4. Clear screen. | + | |
| - | 5. Apply power to VBAT. | + | |
| - | 6. Delay 100ms. | + | |
| - | 7. Send Display On command. | + | |
| ===Power off sequence: | ===Power off sequence: | ||
| - | 1. Send Display Off command. | + | - Send Display Off command. |
| - | 2. Power off VBAT. | + | |
| - | 3. Delay 100ms. | + | |
| - | 4. Power off VDD. | + | |
| The display has a D/C pin (display or command select) that is used to determine whether bytes sent to the display are interpreted as commands or as display data. The D/C pin is set high for display buffer access and low for command access. | The display has a D/C pin (display or command select) that is used to determine whether bytes sent to the display are interpreted as commands or as display data. The D/C pin is set high for display buffer access and low for command access. | ||
| Line 145: | Line 128: | ||
| Appendix B provides sample driver code for initializing the display and writing to it. | Appendix B provides sample driver code for initializing the display and writing to it. | ||
| - | ====Discrete Digital I/O Devices==== | + | ==== 2.2. Discrete Digital I/O Devices==== |
| - | The Basic I/O Shield provides various discrete digital I/O devices. These can be accessed using the digitalRead and digitalWrite | + | The Basic I/O Shield provides various discrete digital I/O devices. These can be accessed using the digitalRead and digitalWrite functions. The pinMode function is used to set the pin to input or output. |
| - | + | ||
| - | functions. The pinMode function is used to set the pin to input or output. | + | |
| When the buttons and switches on the Basic I/O Shield are not being used, the pins are available on the pass-through shield connectors for use by other shields in the stack. The pins used by the LEDs are also available, however the presence of the LEDs on the lines will load them down, possibly causing some devices to not work. It is safe to use any of these pins as either inputs or outputs. | When the buttons and switches on the Basic I/O Shield are not being used, the pins are available on the pass-through shield connectors for use by other shields in the stack. The pins used by the LEDs are also available, however the presence of the LEDs on the lines will load them down, possibly causing some devices to not work. It is safe to use any of these pins as either inputs or outputs. | ||
| - | ===Pushbuttons: | + | **Pushbuttons: |
| - | ===Slide Switches:=== There are four slide switches labeled SW1 (pin 2), SW2 (pin 7), SW3 (pin 8) and SW4 (pin 35). The digitalRead function will return low when the switch is down (toward the pushbuttons) and high when the switch is up (toward the OLED display). | + | **Slide Switches:** There are four slide switches labeled SW1 (pin 2), SW2 (pin 7), SW3 (pin 8) and SW4 (pin 35). The digitalRead function will return low when the switch is down (toward the pushbuttons) and high when the switch is up (toward the OLED display). |
| - | ===LEDs:=== There are eight LEDs labeled LD1 –LD8 that are accessed through digital pins 33 – 26. An LED is illuminated when the corresponding pin is set to high using the digitalWrite function and off when set to low. | + | **LEDs:** There are eight LEDs labeled LD1 –LD8 that are accessed through digital pins 33 – 26. An LED is illuminated when the corresponding pin is set to high using the digitalWrite function and off when set to low. |
| The LEDs are attached to the low eight bits of PORTE, with LD1 connected to PORTE bit 0, and LD8 connected to PORTE bit 7. An 8-bit value written to PORTE (or LATE) will display the corresponding binary value on the LEDs. | The LEDs are attached to the low eight bits of PORTE, with LD1 connected to PORTE bit 0, and LD8 connected to PORTE bit 7. An 8-bit value written to PORTE (or LATE) will display the corresponding binary value on the LEDs. | ||
| - | ====Open Drain FET Outputs==== | + | ==== 2.3. Open Drain FET Outputs ==== |
| The Basic I/O Shield has four open-drain FET outputs. These are low-side N-channel devices and can be used to provide a digital switch closure to ground. These can be used to switch external loads such as relay coils, solenoids, stepper motors, and so on. | The Basic I/O Shield has four open-drain FET outputs. These are low-side N-channel devices and can be used to provide a digital switch closure to ground. These can be used to switch external loads such as relay coils, solenoids, stepper motors, and so on. | ||
| Line 181: | Line 162: | ||
| The unloaded 2-pin header JP1 can be used to connect the shield’s VCC5V0 power supply bus to the external power supply bus so that the shield’s 5V supply can be used instead of an external supply. In this case, J6 is used to connect the shield’s supply to the external loads. If this is done, the total current consumed by all external loads must not exceed 2A or the current rating of the shield’s power supply (whichever is less). | The unloaded 2-pin header JP1 can be used to connect the shield’s VCC5V0 power supply bus to the external power supply bus so that the shield’s 5V supply can be used instead of an external supply. In this case, J6 is used to connect the shield’s supply to the external loads. If this is done, the total current consumed by all external loads must not exceed 2A or the current rating of the shield’s power supply (whichever is less). | ||
| - | ====I2C Bus==== | + | ==== 2.4. I2C Bus ==== |
| The I2C bus from the chipKIT microcontroller board is brought onto the Basic I/O Shield. There are two I2C devices on the board and a connector for taking the I2C bus off the shield to connect to additional external I2C devices. | The I2C bus from the chipKIT microcontroller board is brought onto the Basic I/O Shield. There are two I2C devices on the board and a connector for taking the I2C bus off the shield to connect to additional external I2C devices. | ||
| - | ===I2C Connector:=== Connector J11 can be used to extend the I2C bus off of the shield to connect to additional external I2C devices. J11 is a standard 2x4 pin header connector with 0.100” spaced pins. It provides access to the I2C signals, SCL and SDA, plus VCC3V3 and ground. The VCC3V3 can be used to power external I2C devices. | + | **I2C Connector:** Connector J11 can be used to extend the I2C bus off of the shield to connect to additional external I2C devices. J11 is a standard 2x4 pin header connector with 0.100” spaced pins. It provides access to the I2C signals, SCL and SDA, plus VCC3V3 and ground. The VCC3V3 can be used to power external I2C devices. |
| The I2C bus uses open collector drivers to allow multiple devices to drive the bus signals. This means that pull-up resistors must be provided to supply the logic high state for the signals. The Basic I/O Shield provides 2.2K-ohm pull-up resistors. Generally, only one set of pull-up resistors is used on the bus. Jumpers JP2 and JP3 can be used to disable the on-board pull-up resistors if a different value is needed or some other device on the bus is providing the pull-ups. The on-board pull-up resistors are enabled by install shorting blocks on JP2 and JP3. Removing the shorting blocks disables the pull-up resistors. | The I2C bus uses open collector drivers to allow multiple devices to drive the bus signals. This means that pull-up resistors must be provided to supply the logic high state for the signals. The Basic I/O Shield provides 2.2K-ohm pull-up resistors. Generally, only one set of pull-up resistors is used on the bus. Jumpers JP2 and JP3 can be used to disable the on-board pull-up resistors if a different value is needed or some other device on the bus is providing the pull-ups. The on-board pull-up resistors are enabled by install shorting blocks on JP2 and JP3. Removing the shorting blocks disables the pull-up resistors. | ||
| Line 191: | Line 172: | ||
| Digilent has several small I/O peripheral modules (Pmods) that can be connected using the I2C connector. These include a 3-axis accelerometer, | Digilent has several small I/O peripheral modules (Pmods) that can be connected using the I2C connector. These include a 3-axis accelerometer, | ||
| - | ===EEPROM:=== A 256Kbit (32Kbyte), I2C EEPROM is provided using a Microchip 24LC256. This EEPROM, IC1, is located on the bottom left of the shield, just below the chipKIT logo. | + | **EEPROM:** A 256Kbit (32Kbyte), I2C EEPROM is provided using a Microchip 24LC256. This EEPROM, IC1, is located on the bottom left of the shield, just below the chipKIT logo. |
| The 7-bit I2C device address for the EEPROM is ‘1010000’. | The 7-bit I2C device address for the EEPROM is ‘1010000’. | ||
| Line 199: | Line 180: | ||
| For details on the 24LC256, see the data sheet at www.microchip.com. | For details on the 24LC256, see the data sheet at www.microchip.com. | ||
| - | ===Temperature Sensor:=== A digital temperature sensor is provided using a Microchip TCN75A 2-Wire Serial Temperature Sensor. The temperature sensor, IC2, is an I2C device, and is located in the lower right corner of the shield. | + | **Temperature Sensor:** A digital temperature sensor is provided using a Microchip TCN75A 2-Wire Serial Temperature Sensor. The temperature sensor, IC2, is an I2C device, and is located in the lower right corner of the shield. |
| The TCN75A is rated for an accuracy of +/-1ºC and has selectable resolution from 0.5ºC down to 0.0625ºC. The 7-bit device address is ‘1001000’. | The TCN75A is rated for an accuracy of +/-1ºC and has selectable resolution from 0.5ºC down to 0.0625ºC. The 7-bit device address is ‘1001000’. | ||
| Line 209: | Line 190: | ||
| For complete technical documentation on the TCN75A, see the data sheet available at www.microchip.com. | For complete technical documentation on the TCN75A, see the data sheet available at www.microchip.com. | ||
| - | ====Potentiometer==== | + | ==== 2.5. Potentiometer ==== |
| A potentiometer (pot) is provided on the shield for use as an analog signal source or analog control input. The pot is a 10K-ohm trimmer pot connected between the VCC3V3 supply and ground. The wiper of the pot is connected to analog input A0. | A potentiometer (pot) is provided on the shield for use as an analog signal source or analog control input. The pot is a 10K-ohm trimmer pot connected between the VCC3V3 supply and ground. The wiper of the pot is connected to analog input A0. | ||
| Line 216: | Line 197: | ||
| + | ---- | ||
| + | |||
| + | |||
| + | ===== Appendix A: chipKIT Basic I/O Shield Pinout Table ===== | ||
| + | ^ Uno32 Pin # ^ Max32 Pin # ^ Function | ||
| + | | 10 | 10 | RES | OLED reset | JP4 on Uno32 | | ||
| + | | 39 | 83 | DC | OLED data/ | ||
| + | | 13 | 13 | SCLK | OLED serial clock | ||
| + | | 11 | 11 | SDIN | OLED serial data in | JP7 on Uno32/JP4 on Max32 | | ||
| + | | 40 | 84 | VBAT_EN | ||
| + | | 38 | 82 | VDD_EN | ||
| + | | 33 | 77 | LD1 | User LED | | | ||
| + | | 32 | 76 | LD2 | User LED | | | ||
| + | | 31 | 75 | LD3 | User LED | | | ||
| + | | 30 | 74 | LD4 | User LED | | | ||
| + | | 29 | 73 | LD5 | User LED | | | ||
| + | | 28 | 72 | LD6 | User LED | | | ||
| + | | 27 | 71 | LD7 | User LED | | | ||
| + | | 26 | 70 | LD8 | User LED | | | ||
| + | | 4 | 4 | BTN1 | Pushbutton | ||
| + | | 34 | 78 | BTN2 | Pushbutton | ||
| + | | 36 | 80 | BTN3 | Pushbutton | ||
| + | | 37 | 81 | BTN4 | Pushbutton | ||
| + | | 2 | 2 | SW1 | Slide switch | ||
| + | | 7 | 7 | SW2 | Slide switch | ||
| + | | 8 | 8 | SW3 | Slide switch | ||
| + | | 35 | 79 | SW4 | Slide switch | ||
| + | | 3 | 3 | OC1 | Open drain/PWM output | ||
| + | | 5 | 5 | OC2 | Open drain/PWM output | ||
| + | | 6 | 6 | OC3 | Open drain/PWM output | ||
| + | | 9 | 3 | OC4 | Open drain/PWM output | ||
| + | | 19 | 59 | SCL | I2C clock | JP8 on Uno32/ | ||
| + | | 18 | 58 | SDA | I2C data | JP6 on Uno32/ | ||
| + | | 14 | 54 | A0 | Potentiometer | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== Appendix B: Example Driver Code ===== | ||
| + | The following gives an example of code that initializes the display controller and writes the contents of a memory buffer into the display. This example is written for the chipKIT Uno32 board. | ||
| + | |||
| + | ==== Symbol and Variable Declarations ==== | ||
| + | < | ||
| + | /* ------------------------------------------------------------ */ | ||
| + | /* Pin definitions for access to OLED control signals on chipKIT Uno32 | ||
| + | */ | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | /* ------------------------------------------------------------ */ | ||
| + | /* Symbols describing the geometry of the display. | ||
| + | |||
| + | # | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | /* ------------------------------------------------------------ */ | ||
| + | |||
| + | /* This array is the off-screen frame buffer used for rendering. | ||
| + | ** It isn't possible to read back from the OLED display device, | ||
| + | ** so display data is rendered into this off-screen buffer and then | ||
| + | ** copied to the display. | ||
| + | */ | ||
| + | BYTE rgbOledBmp[cbOledDispMax]; | ||
| + | </ | ||
| + | |||
| + | ==== PIC32 Hardware Initialization ==== | ||
| + | The following function initializes the PIC32 hardware for talking to the display. It initializes the SPI controller and sets the control pins to be outputs. | ||
| + | |||
| + | < | ||
| + | /* ------------------------------------------------------------ */ | ||
| + | / | ||
| + | ** | ||
| + | ** Parameters: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Return Value: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Errors: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Description: | ||
| + | ** Perform PIC32 device initialization to prepare for use | ||
| + | ** of the OLED display. | ||
| + | ** This example is hard coded for the chipKIT Uno32 and | ||
| + | ** SPI2. | ||
| + | */ | ||
| + | |||
| + | void | ||
| + | OledHostInit() | ||
| + | { | ||
| + | unsigned int tcfg; | ||
| + | |||
| + | /* Initialize SPI port 2. | ||
| + | */ | ||
| + | SPI2CON = 0; | ||
| + | SPI2BRG = 15; | ||
| + | SPI2STATbits.SPIROV = 0; | ||
| + | SPI2CONbits.CKP = 1; | ||
| + | SPI2CONbits.MSTEN = 1; | ||
| + | SPI2CONbits.ON = 1; | ||
| + | |||
| + | /* Make pins RF4, RF5, and RF6 be outputs. | ||
| + | */ | ||
| + | PORTSetBits(IOPORT_F, | ||
| + | PORTSetPinsDigitalOut(prtDataCmd, | ||
| + | PORTSetPinsDigitalOut(prtVddCtrl, | ||
| + | PORTSetPinsDigitalOut(prtVbatCtrl, | ||
| + | |||
| + | /* Make the RG9 pin be an output. On the Basic I/O Shield, this pin | ||
| + | ** is tied to reset. | ||
| + | */ | ||
| + | PORTSetBits(prtReset, | ||
| + | PORTSetPinsDigitalOut(prtReset, | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Display Controller Initialization ==== | ||
| + | The following function performs initialization of the display controller on the display panel. This performs the power up sequence on the display and initializes it for a non-interleaved display buffer with the origin in the upper left corner. | ||
| + | |||
| + | < | ||
| + | /* ------------------------------------------------------------ */ | ||
| + | / | ||
| + | ** | ||
| + | ** Parameters: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Return Value: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Errors: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Description: | ||
| + | ** Initialize the OLED display controller and turn the display on. | ||
| + | */ | ||
| + | |||
| + | void | ||
| + | OledDspInit() | ||
| + | { | ||
| + | |||
| + | /* We're going to be sending commands, so clear the Data/Cmd bit | ||
| + | */ | ||
| + | PORTClearBits(prtDataCmd, | ||
| + | |||
| + | /* Start by turning VDD on and wait a while for the power to come up. | ||
| + | */ | ||
| + | PORTClearBits(prtVddCtrl, | ||
| + | DelayMs(1); | ||
| + | |||
| + | /* Display off command | ||
| + | */ | ||
| + | Spi2PutByte(0xAE); | ||
| + | |||
| + | /* Bring Reset low and then high | ||
| + | */ | ||
| + | PORTClearBits(prtReset, | ||
| + | DelayMs(1); | ||
| + | PORTSetBits(prtReset, | ||
| + | |||
| + | /* Send the Set Charge Pump and Set Pre-Charge Period commands | ||
| + | */ | ||
| + | Spi2PutByte(0x8D); | ||
| + | Spi2PutByte(0x14); | ||
| + | |||
| + | Spi2PutByte(0xD9); | ||
| + | Spi2PutByte(0xF1); | ||
| + | |||
| + | /* Turn on VCC and wait 100ms | ||
| + | */ | ||
| + | PORTClearBits(prtVbatCtrl, | ||
| + | DelayMs(100); | ||
| + | |||
| + | /* Send the commands to invert the display. This puts the display origin | ||
| + | ** in the upper left corner. | ||
| + | */ | ||
| + | Spi2PutByte(0xA1); | ||
| + | Spi2PutByte(0xC8); | ||
| + | |||
| + | /* Send the commands to select sequential COM configuration. This makes the | ||
| + | ** display memory non-interleaved. | ||
| + | */ | ||
| + | Spi2PutByte(0xDA); | ||
| + | Spi2PutByte(0x20); | ||
| + | |||
| + | /* Send Display On command | ||
| + | */ | ||
| + | Spi2PutByte(0xAF); | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | ==== Display Memory Update ==== | ||
| + | This function copies the contents of a 512-byte buffer from PIC32 memory to the display. The display memory is organized as four pages of 128 bytes each. Each memory page corresponds to an 8-pixel-high stripe across the display. Each byte in the memory page corresponds to an 8-pixel-high column on the display. The least significant bit in a display byte is the top most pixel, and the most significant bit the bottom most pixel. The first byte in the page corresponds to the left most pixels on the display and the last byte the right most pixels. | ||
| + | |||
| + | This function assumes that the display buffer to be copied is the global variable rgbOledBmp. | ||
| + | |||
| + | < | ||
| + | /* ------------------------------------------------------------ */ | ||
| + | / | ||
| + | ** | ||
| + | ** Parameters: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Return Value: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Errors: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Description: | ||
| + | ** Update the OLED display with the contents of the memory buffer | ||
| + | */ | ||
| + | |||
| + | void | ||
| + | OledUpdate() | ||
| + | { | ||
| + | int ipag; | ||
| + | int icol; | ||
| + | BYTE * pb; | ||
| + | |||
| + | pb = rgbOledBmp; | ||
| + | |||
| + | for (ipag = 0; ipag < cpagOledMax; | ||
| + | |||
| + | PORTClearBits(prtDataCmd, | ||
| + | |||
| + | /* Set the page address | ||
| + | */ | ||
| + | Spi2PutByte(0x22); | ||
| + | Spi2PutByte(ipag); | ||
| + | |||
| + | /* Start at the left column | ||
| + | */ | ||
| + | Spi2PutByte(0x00); | ||
| + | Spi2PutByte(0x10); | ||
| + | |||
| + | PORTSetBits(prtDataCmd, | ||
| + | |||
| + | /* Copy this memory page of display data. | ||
| + | */ | ||
| + | OledPutBuffer(ccolOledMax, | ||
| + | pb += ccolOledMax; | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== Low-level SPI Functions ==== | ||
| + | The following functions are used to write data to the display panel using the SPI controller. | ||
| + | |||
| + | < | ||
| + | /* ------------------------------------------------------------ */ | ||
| + | / | ||
| + | ** | ||
| + | ** Parameters: | ||
| + | ** cb - number of bytes to send/ | ||
| + | ** rgbTx - pointer to the buffer to send | ||
| + | ** | ||
| + | ** Return Value: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Errors: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Description: | ||
| + | ** Send the bytes specified in rgbTx to the slave. | ||
| + | |||
| + | */ | ||
| + | |||
| + | void | ||
| + | OledPutBuffer(int cb, BYTE * rgbTx) | ||
| + | { | ||
| + | int ib; | ||
| + | BYTE bTmp; | ||
| + | |||
| + | /* Write/Read the data | ||
| + | */ | ||
| + | for (ib = 0; ib < cb; ib++) { | ||
| + | /* Wait for transmitter to be ready | ||
| + | */ | ||
| + | while (SPI2STATbits.SPITBE == 0); | ||
| + | |||
| + | /* Write the next transmit byte. | ||
| + | */ | ||
| + | SPI2BUF = *rgbTx++; | ||
| + | |||
| + | /* Wait for receive byte. | ||
| + | */ | ||
| + | while (SPI2STATbits.SPIRBF == 0); | ||
| + | bTmp = SPI2BUF; | ||
| + | |||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | /* ------------------------------------------------------------ */ | ||
| + | / | ||
| + | ** | ||
| + | ** Parameters: | ||
| + | ** bVal - byte value to write | ||
| + | ** | ||
| + | ** Return Value: | ||
| + | ** Returns byte read | ||
| + | ** | ||
| + | ** Errors: | ||
| + | ** none | ||
| + | ** | ||
| + | ** Description: | ||
| + | ** Write/ | ||
| + | */ | ||
| + | |||
| + | BYTE | ||
| + | Spi2PutByte(BYTE bVal) | ||
| + | { | ||
| + | BYTE bRx; | ||
| + | |||
| + | /* Wait for transmitter to be ready | ||
| + | */ | ||
| + | while (SPI2STATbits.SPITBE == 0); | ||
| + | |||
| + | /* Write the next transmit byte. | ||
| + | */ | ||
| + | SPI2BUF = bVal; | ||
| + | |||
| + | /* Wait for receive byte. | ||
| + | */ | ||
| + | while (SPI2STATbits.SPIRBF == 0); | ||
| + | |||
| + | /* Put the received byte in the buffer. | ||
| + | */ | ||
| + | bRx = SPI2BUF; | ||
| + | |||
| + | return bRx; | ||
| - | ===Appendix A: chipKIT Basic I/O Shield Pinout Table=== | + | } |
| + | </code> | ||

