PSoc _read() query

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi Guys,

   

First time poster/noob,

   

Ive got a PSoC 1 eval kit and I am generally used to the MSP430 but I started using PSoC programs,

   

I was just wondering how to use the _Read() and _Write() API's correctly.

   

I have an LED on Port1.0 and normally I would use the following to set port to High: PRT1DR &= ~0x01;

   

I changed the name of Port1.0 in the PSoC pinout page to led,

   

Can i simply just use the following to make the port pin high?

   

led_write(1);

   

 

   

thanks

0 Likes
6 Replies
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

 Hi,

   

 

   

The simplest method of controlling an LED is to add a LED usermodule.

   

 

   

From the userdmodule window, expand "Misc Digital", and double click on "LED" to place it.

   

 

   

Use the "parameters" window to set a name to your LED and assign the pin and the active low/high logic. Press Ctrl+F6 to generate the usermodule files.

   

 

   

 

   

From your code, you can now use LEDname_On and LEDname_Off to switch your LED on and off (LEDname is the name you give to the usermodule)

   

 

   

 

   

Happy coding!

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

If you perform read modify write operations on a port you need

   

to use shadow registers -

   

 

   

http://www.cypress.com/?rID=39497

   

      http://www.planetpsoc.com/psoc1-articles-digital/13-basics-of-psoc-gpio.html?start=5

   

 

   

Regards, Dana

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Forgot to add, if port has mixed I/O in it.

   

 

   

Regards, Dana.

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

Using an LED usermodule automatically takes care of the Shadow register issue (if you want a quick intro to what shadow registers are all about, check out the second video on this page - http://www.cypress.com/?rID=2900)

   

 

   

 

   

But as per your post, if you want to avoid using a usermodule/shadow registers for some reason and use just the pin name, you can use the following code to control a pin-

   

 

   

led_Data_ADDR |= led_MASK;  

   

led_Data_ADDR &= (~led_MASK);  

   

// where "led" is the name you had given in the Pinout window, also check that Drive should be "Strong" for a digital output

   

 

   

The _Data_ADDR and _MASK are MACROS that are generated automatically, when you assign a name to a pin.

   

 

   

 

   

Note that advantage of this method is that you can also use for an input pin (configured as High-Z) for a read operation:

   

 

   

pinStatus = inputPin_Data_ADDR & inputPin_MASK;  

0 Likes
Anonymous
Not applicable

Hi Guys,

   

Thanks for your replies, really appreciate it!

   

I have an LED on the output at them moment but the output may be used to send a signal to a transistor or otehr devices.

   

ill have a look through the links sent

   

thanks again guys

0 Likes
Anonymous
Not applicable

Using the Led user module even if you don't use mixed I/O on the port will save you a lot of trouble. I mean, if eventually you decide to have a pull-up on the next port pin, the shadow register will be automatically updated by using LedName_On(); or LedName_Off();. You won't need to care about read/modify/write issue.

0 Likes