GPIO Help

A catchall for PSoC Mixed-Signal Array (microcontroller) discussions not captured by the other forums.

Moderator: ericb

GPIO Help

Postby suniljha on Tue Jan 27, 2004 8:07 am

Hi!
I am trying to set pin 7 of port 2 as digital output to control LCD backlight through switching transistor. In PSoC designer's Device Editor Window I set P2[7] as Strong. Now I am using PRT2DR|0x80 and PRT2DR&0x7F to ON and OFF the backlight. But there is no action. I would like to know that is there any need to write to PRT2DM[2:0] = 001 after setting P2[7] as strong drive in Device Editor? If not then what should be the settings/steps for using a GPIO pin for digital output?

waiting for help..
regards,
Sunil
suniljha
Cheese Cube
Cheese Cube
 
Posts: 45
Joined: Wed Dec 24, 2003 5:44 am
Location: INDIA

Postby steve on Tue Jan 27, 2004 9:17 am

Are you using expressions or assignment operators?

Code: Select all
// Expressions calculate a temporary value
// but don't update PRT2DR
PRT2DR | 0x80;
PRT2DR & 0x7f;

// Assignment operators modify the data in the
// PRT2DR output latches.
PRT2DR |=  0x80;
PRT2DR &= ~0x7f;


Steve
steve
Cheese Cube
Cheese Cube
 
Posts: 55
Joined: Thu Dec 11, 2003 4:44 pm

Postby suniljha on Tue Jan 27, 2004 8:04 pm

Hi Steve,
I am using assignment operator. Sorry for missing it my last posting. I am using

PRT2DR |= 0x80;
PRT2DR &= ~0x7f;

to make P2[7] =1/0. Is there any other way to do this? At present I am not able to change state of selective I/O pin of a port. Please help..if any other settings required.

Sunil
suniljha
Cheese Cube
Cheese Cube
 
Posts: 45
Joined: Wed Dec 24, 2003 5:44 am
Location: INDIA

Postby baxsie on Tue Jan 27, 2004 9:47 pm

Is there other code accessing PRT2DR ? Especially code in an ISR?
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Postby suniljha on Wed Jan 28, 2004 1:45 am

Hi baxsie!
I have not written any code for using PRT2DR. I don't know about it if PSoC Designer generate it by default. I am looking for help to get digital 1 or 0 on a pin of PSoC. If anyone have this simple code then please upload in download section.

Bye!
Sunil
suniljha
Cheese Cube
Cheese Cube
 
Posts: 45
Joined: Wed Dec 24, 2003 5:44 am
Location: INDIA

Postby suniljha on Wed Jan 28, 2004 1:49 am

Sorry to tell you that I am using PORT 2 for LCD module. But as it requires only 7 GPIO pins Port2[0:6] I planned to used 8th pin of PORT2 for backlight control. Is it giving any clue??

Bye!
Sunil
suniljha
Cheese Cube
Cheese Cube
 
Posts: 45
Joined: Wed Dec 24, 2003 5:44 am
Location: INDIA

Postby baxsie on Wed Jan 28, 2004 6:38 am

Disable the LCD stuff and see if the bscklight starts working.
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Postby wes on Wed Jan 28, 2004 10:37 am

Have you checked to see if the port bit is changing with a probe or 'scope? Have you tried it with the LCD module disconnected so you are measuring only the pin?

You might also want to try this just to be sure:
PRT2DR = 0x80;
PRT2DR = 0x00;

Reading the port can tell you if something is forcing the bit to a particular state.

I have used bit 7 successfully with the LCD user module running bits [6:0].

Regards,
Wes
Last edited by wes on Tue Apr 26, 2005 10:47 am, edited 1 time in total.
wes
The Big Cheese
The Big Cheese
 
Posts: 248
Joined: Sun Dec 14, 2003 1:37 am
Location: Washington

Postby steve on Wed Jan 28, 2004 2:19 pm

I've uploaded an example project that does GPIO reads and writes from C. It's in the downloads example projects section under "GPIO Read and Write".

Give it a try. I've seen it working on my desk, just minutes ago.

Steve
steve
Cheese Cube
Cheese Cube
 
Posts: 55
Joined: Thu Dec 11, 2003 4:44 pm

lcd back light

Postby Rishi Kumar on Wed Jan 28, 2004 9:56 pm

HI Sunil
It is better to send your code.

Rishi Kumar
Rishi Kumar
Bite-Size Cheese
Bite-Size Cheese
 
Posts: 13
Joined: Mon Jan 05, 2004 11:39 pm
Location: India,Delhi

Postby suniljha on Fri Jan 30, 2004 9:23 am

Hi Wes!
You have mentioned that "I have used bit 7 successfully with the LCD user module running bits [6:0]." but as per
JMM's Posting on Cypress Forum he wrote "I convinced myself that trying to use the "unused" bit 7 of the LCD port wasn't possible without modifying the Cypress provided LCD code".

Can you please let me know if you have done any modification in LCD User Module to use bit 7?

Bye!
Sunil
suniljha
Cheese Cube
Cheese Cube
 
Posts: 45
Joined: Wed Dec 24, 2003 5:44 am
Location: INDIA

Postby baxsie on Fri Jan 30, 2004 11:25 am

You pretty much have to use "port mirrors" to make the ports consistent on the PSoC:

utils.h:

typedef unsigned char ubyte;
//These are mirror register variables that allow reliable read-modify-write
//operations (setting and clearing individual bits) to the I/O ports.
extern ubyte port0; //mirror of bank 0, REG[0x00]
extern ubyte port1; //mirror of bank 0, REG[0x04]
extern ubyte port2; //mirror of bank 0, REG[0x08]

utils.c:

//These are mirror register variables that allow reliable read-modify-write
//operations (setting and clearing individual bits) to the I/O ports.
ubyte
port0; //mirror of bank 0, REG[0x00]
ubyte
port1; //mirror of bank 0, REG[0x04]
ubyte
port2; //mirror of bank 0, REG[0x08]

. . .

void Initilaize_Ports(void)
{
//Initialize all the ports and their mirrors.
PRT0DR=(port0=0x00);
PRT1DR=(port1=0x00);
PRT2DR=(port2=0x00);
. . .
}

Typical set, clear and assignment code:

#include "utils.h"
. . .
PRT0DR=(port0|=0x10);
PRT0DR=(port0&=~0x10);
PRT0DR=(port0=0x00);

Another PSoC port access "gotcha":
http://www.cypress.com/forums/messagevi ... adid=10075

Rambling "bitch & moan" port structure thread:
http://www.cypress.com/forums/messagevi ... eadid=1929

RMW port access thread (oh look, July of 2001 :) ) :
http://www.cypress.com/forums/messagevi ... readid=679
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Postby wes on Fri Jan 30, 2004 10:38 pm

Hi Sunil,

My software-only 1-Wire user module, OneWireSW, will work with bit 7 of a port while the LCD user module uses bits [6:0]. I tried using the same port just now and it still works. Now that I have examined my code again I remember that this was not easy to do. I use the same shadow registers as the LCD code to keep the two sets of code from interfering with each other.

The shadow registers are basically the same thing as the "port mirrors" that Baxsie described. The main difference is that PSoC Designer helps to make them work for user modules. That is the catch. In fact, it was my wanting to use bit 7 while the LCD used bits [6:0] that got me to write the OneWireSW user module. :)

Modifying the LCD code may be an easier way for you to get what you want. There may be another way to use bit 7 as a backlight control. I will try to find out if there is a better solution.

Regards,
Wes
wes
The Big Cheese
The Big Cheese
 
Posts: 248
Joined: Sun Dec 14, 2003 1:37 am
Location: Washington

Postby wes on Mon Feb 02, 2004 4:29 pm

Hi Sunil,

The shadow registers in the LCD user module must be used if you want to use bit 7 of the LCD GPIO port. The display could malfunction otherwise. I may know a way to add the backlight control without changing the LCD code. I will let you know if it works.

Regards,
Wes
wes
The Big Cheese
The Big Cheese
 
Posts: 248
Joined: Sun Dec 14, 2003 1:37 am
Location: Washington

Postby wes on Mon Feb 02, 2004 11:39 pm

Hi Sunil,

I found a way to control bit 7 on the same port as the LCD. It does not require any changes to the LCD user module.

1. Select and set the parameters for the LCD user module.

2. In the pin parameters of PSoC Designer (lower left panel in the interconnect view):
a. Give bit 7 a name, it will be called Port_#_7 by default, for example BL_CTRL.
b. Set the drive mode in the "Drive" column.
c. Click the Generate application button.
This sets up definitions for the shadow registers for the BL_CTRL pin. The shadow registers will be mapped to the same ones used by the LCD code.

For C, the definitions will be in the file PSoCGPIOINT.h.
For assembly, macros will be defined in the file PSoCGPIOINT.inc.

3. In your main.c file:

Code: Select all
#include "PSoCGPIOINT.h"
...
BL_CTRL_Data_ADDR=(BL_CTRL_DataShadow|=BL_CTRL_MASK);    // Set BL_CTRL pin
BL_CTRL_Data_ADDR=(BL_CTRL_DataShadow&=~BL_CTRL_MASK);   // Clear BL_CTRL pin


The names BL_CTRL_Data_ADDR, BL_CTRL_DataShadow, and BL_CTRL_MASK are defined by PSoC Designer based on the name supplied in step 2a.

For assembly, macros named SetBL_CTRL_Data, and ClearBL_CTRL_Data are defined in the file PSoCGPIOINT.inc. Add the line include: "PSoCGPIOINT.inc" to your main.asm file.

Regards,
Wes
wes
The Big Cheese
The Big Cheese
 
Posts: 248
Joined: Sun Dec 14, 2003 1:37 am
Location: Washington

Postby wes on Mon Feb 02, 2004 11:56 pm

The shadow registers for the port data and drive mode will be initialized automatically because of the LCD user module.
wes
The Big Cheese
The Big Cheese
 
Posts: 248
Joined: Sun Dec 14, 2003 1:37 am
Location: Washington

Postby ramkitty on Tue May 03, 2005 5:57 pm

you would think it would be easier to set a bit
ramkitty
Cheese Cube
Cheese Cube
 
Posts: 39
Joined: Fri Apr 08, 2005 11:34 am
Location: bc canada

Postby baxsie on Wed May 04, 2005 8:27 am

Yes, you would.
I'm not getting older. I'm getting bitter.
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Postby craign on Wed May 04, 2005 10:09 am

Ramkitty - Baxsie -

Yes, you'd think it would be easier. "Ease of use " is only one axis for measuring performance. "Flexibility" and "silicon area" are also important. In this case, "silicon area" won out by a landslide. There are a lot of ways to make the interface simpler, but they chow through silicon in a hurry. There aren't many high volume customers who are willing to accept a large increase in cost without adding chip features.

Engineering often requires evaluating tradeoffs. In this case, the lesser of many weevils is a rather annoying weevil.
regards,
-Craig
User avatar
craign
The Big Cheese
The Big Cheese
 
Posts: 231
Joined: Thu Dec 11, 2003 7:51 pm
Location: Between Jeff (formerly Steve) and Galen (formerly Eric)

Postby baxsie on Wed May 04, 2005 10:41 am

{baxsie's hot button gets pushed :) }
I cannot believe that having 5 "read output latch" registers could eat that much silicon.

It could be done in micro-code and 5 RAM locations, since I can do it in firmware and 5 mirror/shadow registers.

Part cost is also affected by code efficiency. If you have an ISR that accesses a port, this is the minimum safe code to set a bit (_port0 is the mirror):
Code: Select all
  OR  [_port0],0x20
  AND F,~0x01       ;CLI
  MOV A,[_port0]
  MOV REG[0],A
  OR  F,0x01        ;STI
And that code still destroys the accumulator. It would be nice if there were a new instruction added that could implement that snippet, with 5 dedicated (and hidden) registers that would automatically get updated by writes to the ports, and accessed by RMW port access.

. . . . just dreaming of course :)
I'm not getting older. I'm getting bitter.
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Next

Return to PSoC1 General

Who is online

Users browsing this forum: Bing [Bot] and 0 guests

cron