Jump to content
43oh

SOLVED - Writing and Reading the Values of an 8-bit Port with Energia


Recommended Posts

Problem solved!

 

I'd like to write and read the 8 bits of PB port on the LaunchPad Stellaris at once.

 

On the Arduino Meag2560, I can write and read the values of an 8-bit port, for example PORTC.

void LCD_HI32::_writeParallelLCD88(uint8_t dataHigh8, uint8_t dataLow8)
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    PORTA = dataHigh8;
    PORTC = dataLow8;
    pulse_low(_portWR, _bitWR);
#else
//#error Platform not supported.
#endif
}

void LCD_HI32::_readParallelLCD88(uint8_t &dataHigh8, uint8_t &dataLow8)
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    pulse_low(_portRS, _bitRS);
    dataHigh8 = PORTA;
    dataLow8 = PORTC;
#else
//#error Platform not supported.
#endif
}

For the MSP430, 

  uint8_t value = 2;
  P1OUT = value;
  value = P1IN;

What are the corresponding variables for Stellaris? Thank you.

Link to post
Share on other sites

@Mention,

 

Here is what I use for my LCD driver. Note the last line.  Remember  HWREG is your friend.  A good way to do fast digital I/O. :)

 

//========================================// Port and bitmask used for 8-bit data bus#define LCD_DATA_PERIPH         SYSCTL_PERIPH_GPIOB#define LCD_DATA_BASE           GPIO_PORTB_BASE#define LCD_DATA_PINS           0xFF// Ports and pins used for control#define LCD_CS_PERIPH           SYSCTL_PERIPH_GPIOA#define LCD_CS_BASE             GPIO_PORTA_BASE#define LCD_CS_PIN              GPIO_PIN_7#define LCD_CD_PERIPH           SYSCTL_PERIPH_GPIOA#define LCD_CD_BASE             GPIO_PORTA_BASE#define LCD_CD_PIN              GPIO_PIN_6#define LCD_WR_PERIPH           SYSCTL_PERIPH_GPIOA#define LCD_WR_BASE             GPIO_PORTA_BASE#define LCD_WR_PIN              GPIO_PIN_5#define LCD_RD_PERIPH           SYSCTL_PERIPH_GPIOA#define LCD_RD_BASE             GPIO_PORTA_BASE#define LCD_RD_PIN              GPIO_PIN_4#define LCD_RST_PERIPH          SYSCTL_PERIPH_GPIOC#define LCD_RST_BASE            GPIO_PORTC_BASE#define LCD_RST_PIN             GPIO_PIN_7#define LCD_BKLT_PERIPH         SYSCTL_PERIPH_GPIOD#define LCD_BKLT_BASE           GPIO_PORTD_BASE#define LCD_BKLT_PIN            GPIO_PIN_6#define LCD_CS_IDLE             HWREG(LCD_CS_BASE + GPIO_O_DATA + (LCD_CS_PIN << 2)) = LCD_CS_PIN;#define LCD_CS_ACTIVE           HWREG(LCD_CS_BASE + GPIO_O_DATA + (LCD_CS_PIN << 2)) = 0;#define LCD_CD_DATA             HWREG(LCD_CD_BASE + GPIO_O_DATA + (LCD_CD_PIN << 2)) = LCD_CD_PIN;#define LCD_CD_COMMAND          HWREG(LCD_CD_BASE + GPIO_O_DATA + (LCD_CD_PIN << 2)) = 0;#define LCD_WR_IDLE             HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = LCD_WR_PIN;#define LCD_WR_ACTIVE           HWREG(LCD_WR_BASE + GPIO_O_DATA + (LCD_WR_PIN << 2)) = 0;#define LCD_RD_IDLE             HWREG(LCD_RD_BASE + GPIO_O_DATA + (LCD_RD_PIN << 2)) = LCD_RD_PIN;#define LCD_RD_ACTIVE           HWREG(LCD_RD_BASE + GPIO_O_DATA + (LCD_RD_PIN << 2)) = 0;#define LCD_RST_IDLE            HWREG(LCD_RST_BASE + GPIO_O_DATA + (LCD_RST_PIN << 2)) = LCD_RST_PIN;#define LCD_RST_ACTIVE          HWREG(LCD_RST_BASE + GPIO_O_DATA + (LCD_RST_PIN << 2)) = 0;#define LCD_BKLT_ON             HWREG(LCD_BKLT_BASE + GPIO_O_DATA + (LCD_BKLT_PIN << 2)) = LCD_BKLT_PIN;#define LCD_BKLT_OFF            HWREG(LCD_BKLT_BASE + GPIO_O_DATA + (LCD_BKLT_PIN << 2)) = 0;#define LCD_DATA_WRITE(ucByte)  { HWREG(LCD_DATA_BASE + GPIO_O_DATA + (LCD_DATA_PINS << 2)) = (ucByte); }

 

Link to post
Share on other sites

Not sure in Energia, using stellarisware you read it as

 

GPIOPinRead(GPIO_PORTB_BASE, 0xFF)

 
which translates to 
 
(HWREG( GPIO_PORTB_BASE  + (GPIO_O_DATA + (0xFF << 2))));

 

 

Edit - ignore this post, others answered while it was sitting in my browser.  Don't see a way to delete.

Link to post
Share on other sites

Thank you very much for the clear indications and explanations.

 

As rightly pointed by @@chicken, the following pre-processing statement is required:

#include "inc/lm4f120h5qr.h"

Without going as deep as recommended by @@jkabat, the functions mentioned by @@igor are available in Energia in the gpio.c library:

GPIODirModeSet(unsigned long ulPort, unsigned char ucPins,
               unsigned long ulPinIO)

GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal)

GPIOPinRead(unsigned long ulPort, unsigned char ucPins)

Yes, this is for a 8-bit parallel screen :)

Link to post
Share on other sites
  • 2 weeks later...

Here is what I use for my LCD driver. Note the last line.  Remember  HWREG is your friend.  A good way to do fast digital I/O. 

 

 

 

Thank you @@jkabat for pointing me on this interesting direction.

 

At first, I was afraid by such low-level HWREG instructions but once I get used to them, I really enjoy how fast they are!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...