Author Topic: == SPI C Source Code for using I/Os ==  (Read 7947 times)

modtro2

  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
== SPI C Source Code for using I/Os ==
« on: November 27, 2006, 07:43:09 PM »
The following C Source code uses the spiPutGetByte() function defined in the following post:
http://forum.modtronix.com/index.php?topic=399.0
For it to work, you will have to add the spiPutGetByte() function to your code too!

The LCD2S has two high current, 1000mA open collector outputs (OUT1 and OUT2) and three configurable general purpose inputs/outputs (GPIO1 to GPIO3). OUT1 and OUT2 have output protection diodes, and can be used to directly drive relays. OUT2 is always enabled. OUT1, GPIO1, GPIO2 and GPIO3 share port pins with the keypad encoder, and can not all be used when the keypad encoder is enabled. For details, see the LCD2S documentation. Following are some common examples how to configure and use the inputs, outputs and keypad encoder.


Use OUT2
The following example shows how to use OUT2 as an output. The OUT2 output is always enabled, and no configuration is required. The code for using OUT2 is:
Code: [Select]
    //OUT2 on = will activate open collector output, and pull ouput to ground
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x39);

    //OUT2 off = will switch off open collector output, output will become high impedance
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x31);


Use OUT1, and configure for 4x3 keypad
The following example shows how to use OUT1(OUT2 is always enabled) as an output. When using OUT1, the maximum keypad that can be used is 12 keys (4 rows by 3 columns). Additionally jumper J1 on the back of the LCD2S board has to be inserted for OUT1 to work! To configure this we have to send a "Configure Keypad and I/O" command to the LCD2S. This command must always be preceded by a "Remember" command. The code for configuring the LCD2S is:

Code: [Select]
    //Send "Remember Command" - "Configure Keypad and I/O" command must be preceded by a remember command
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x8D);     //"Remember" command

    //Configure keypad for 4 rows by 3 column, enable OUT1
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0xE0);     //"Configure Keypad and I/O" command
    spiPutGetByte(0x01);     //Parameter for "Configure Keypad and I/O" command - 0x01 = 4x3 keypad, OUT1 enabled

The following code can then be used to set and clear the OUT1 output.
Code: [Select]
    //OUT1 on = will activate open collector output, and pull ouput to ground
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x38);

    //OUT1 off = will switch off open collector output, output will become high impedance
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x30);


Use OUT1, GPIO1 and GPIO2 as general purpose outputs
The following example shows how to use OUT1 (OUT2 is always enabled), GPIO1 and GPIO2 as outputs. Because all inputs and outputs are used, the keypad will be disabled. Additionally jumper J1 on the back of the LCD2S board has to be inserted for OUT1 to work! To configure this we have to send a "Configure Keypad and I/O" command to the LCD2S. This command must always be preceded by a "Remember" command. The code for configuring the LCD2S is:

Code: [Select]
    //Send "Remember Command" - "Configure Keypad and I/O" command must be preceded by a remember command
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x8D);     //"Remember" command

    //Configure keypad for 4 rows by 1 column, enable OUT1, GPIO1 and GPIO2
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0xE0);     //"Configure Keypad and I/O" command
    spiPutGetByte(0x07);     //Parameter for "Configure Keypad and I/O" command - 0x07 = 4x1 keypad

    //Send "Remember Command" - "Configure GPIO1" command must be preceded by a remember command
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x8D);     //"Remember" command

    //Configure GPIO1 as an output
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0xE3);     //"Configure GPIO1" command
    spiPutGetByte(0x01);     //Parameter for "Configure GPIO1" command - 0x01 = Digital output

    //Send "Remember Command" - "Configure GPIO2" command must be preceded by a remember command
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x8D);     //"Remember" command

    //Configure GPIO2 as an output
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0xE4);     //"Configure GPIO2" command
    spiPutGetByte(0x01);     //Parameter for "Configure GPIO2" command - 0x01 = Digital output

The following code can then be used to set and clear the OUT1, OUT2, GPIO1 and GPIO2 outputs.
Code: [Select]
    //OUT1 on = will activate open collector output, and pull ouput to ground
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x38);

    //OUT1 off = will switch off open collector output, output will become high impedance
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x30);

    //GPIO1 high = will set GPIO1 to +5V
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x48);

    //GPIO1 low = will set GPIO1 to 0V
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x40);

    //GPIO2 high = will set GPIO2 to +5V
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x49);

    //GPIO2 low = will set GPIO2 to 0V
    spiPutGetByte(0xF5);     //Sync byte - each SPI command has to start with this byte!
    spiPutGetByte(0x41);

« Last Edit: November 27, 2006, 08:20:42 PM by modtro2 »

Aletstero

  • Jr. Member
  • **
  • Posts: 9
    • View Profile
SPI C Source Code for using I/Os
« Reply #1 on: December 07, 2009, 03:23:19 AM »
Soo have you tried a 20 some odd inch monitor to see the differance?