Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 1 > PSoc _read() query

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



PSoc _read() query
Moderator:
ARVI

Post Reply
Follow this topic



PSoc _read() query

Cf_corp posted on 16 Aug 2012 3:33 AM PST
Top Contributor
74 Forum Posts

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




Re: PSoc _read() query

arvi posted on 16 Aug 2012 04:55 AM PST
Cypress Employee
119 Forum Posts

 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!



Re: PSoc _read() query

danaaknight posted on 16 Aug 2012 05:28 AM PST
Top Contributor
1773 Forum Posts

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

 



Re: PSoc _read() query

danaaknight posted on 16 Aug 2012 05:30 AM PST
Top Contributor
1773 Forum Posts

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

 

Regards, Dana.



Re: PSoc _read() query

arvi posted on 16 Aug 2012 05:48 AM PST
Cypress Employee
119 Forum Posts

 

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;  



Re: PSoc _read() query

Cf_corp posted on 16 Aug 2012 05:53 AM PST
Top Contributor
74 Forum Posts

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



Re: PSoc _read() query

EricS posted on 16 Aug 2012 12:51 PM PST
Top Contributor
46 Forum Posts

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.

 

 






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20