Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 5 > PSoC 5 C functions list and examples

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



PSoC 5 C functions list and examples
Moderator:
ANCY

Post Reply
Follow this topic



PSoC 5 C functions list and examples

Tariq posted on 01 Dec 2012 8:54 AM PST
Member
7 Forum Posts

 Hi 

I started using a PSoC 5 kit a week back. I am looking for a list of available c functions (e.g. CyDelay) for programming PSoC 5. I searched using google and cypress website but so faor did not find a user manual or guid on available c functions.  Where can I find that?  Thanks. Tariq




Re: PSoC 5 C functions list and examples

Bob Marlowe posted on 01 Dec 2012 09:29 AM PST
Top Contributor
1768 Forum Posts

The entry-point for PSoC5 is the Creator-software which you may download for free from here:

http://www.cypress.com/?id=2494&source=header

Assuming you already installed and are using Creator 2.1 which will show you a long of hardware modules. In the datasheet of each module is a description for all its APIs.

 

Under "Help-> Documentation -> System Reference -> System Reference Guide" you'll find some more, deeper information about what's going on within the PSoCs.

In the Video-Corner there are nearly 100 intros to the different aspects of PSoCs (to be found at the top of this page under "Support -> Videos & Technical Training" 

 

And for all further questions: Do not hesitate to ask us.

 

Happy coding

Bob



Re: PSoC 5 C functions list and examples

danaaknight posted on 01 Dec 2012 09:56 AM PST
Top Contributor
1773 Forum Posts

http://www.cypress.com/?app=forum&id=2232&rID=50124

 

System Reference Guide under help, page 68.

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

PSoC Rocks posted on 03 Dec 2012 10:46 AM PST
Top Contributor
128 Forum Posts

 You can also refer to cytypes.c, cyutils.c, CyLib.c under Generated source for more information on the source code.



Re: PSoC 5 C functions list and examples

Tariq posted on 04 Dec 2012 05:36 AM PST
Member
7 Forum Posts
Thanks a lot for all your replies. PSoC creator help is not good. For example I am trying to configure ports and write directly to port. (port 0, I have LEDs connected to port 0) In the connection diagram there is no was to connect a port. It is always a pin connection. So far I cannot useful details on how to write directly to a port as we do in PIC microcontroller / arduino. Is there any book on PSoC 5 that I can read. Amazon is not showing me any book. Thanks Tariq

Re: PSoC 5 C functions list and examples

Bob Marlowe posted on 04 Dec 2012 06:20 AM PST
Top Contributor
1768 Forum Posts

I suppose, some of your difficulties you have got are resulting from "Thinking PIC" and not from "Thinking PSoC". The way to specify usermodules and connect them together to build your desired functionality differs a lot from what you were used to.

Help for PSoC Creator is not only where you usually find it (under the Help-Button) but each (!!!) usermodule has got its own datasheet which is just two mousclicks away: Left-Click any usermodule on your schematic or in the module list and select "Datasheet". All datasheets are organizes similarily: What the module is good for, how to set properties, API list, electrical characteristics and so on.

Even the Pin-component has got a datasheet which directs you to the System Reference Guide where you are told how to access ports (if you really need to). Reading or writing to a complete port is usually done when you are expecting 8 Bits to work on, if it is less there are better solutions. When accessing a port directly you may loose some of the flexibility in design which lets you easily swap pins without having to change your code.

There is a lot more to say about, the easiest would be if you tell us, what problem you'd like to solve and if you want us all to have a look at, upload your project here (with Creator-> file ->Create workspace bundle (minimal) and the uploading the resulting Zip -archive here.

 

Happy coding

Bob



Re: PSoC 5 C functions list and examples

danaaknight posted on 04 Dec 2012 08:01 AM PST
Top Contributor
1773 Forum Posts

An ap note on GPIO -

 

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

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

Tariq posted on 09 Dec 2012 10:45 AM PST
Member
7 Forum Posts

 Thanks Dana. I have already read that application note. 

 

Bob, here is a copy of my simple code that generate 16 errors.

 

#include <device.h>
 
void main()
{
       int i;  
       /* set PORT0 to strong drive move */ 
       PRT0DM0= 0xFF; 
       PRT0DM1= 0x00; 
       PRT0DM2= 0x00;
        while (1);{
        for ( i = 0; i < 256; i++ ){ 
        PRT0DR= 0xFF; 
        CyDelay(500);
        PRT0DR= 0x00;
        CyDelay(500);
        }  
        }
}
/* [] END OF FILE */



Re: PSoC 5 C functions list and examples

danaaknight posted on 09 Dec 2012 11:06 AM PST
Top Contributor
1773 Forum Posts

This

 

   while (1);{

 

Shoukld be

 

   while (1) {

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

Bob Marlowe posted on 09 Dec 2012 01:10 PM PST
Top Contributor
1768 Forum Posts

I suggestedd to create a workspace bundle. This helps to see what you have defined for your port(s).

The way you are accessing the port's mode is a bit unusual for PSoCs but should work. Let us see the complete project. Dana's hint for the while dead-loop is correct.

 

Bob



Re: PSoC 5 C functions list and examples

Tariq posted on 09 Dec 2012 01:13 PM PST
Member
7 Forum Posts

 Thanks Dana for identifying a basic mistake.  My errors are shown in the attached file.

 

In another example I connected a k type thermocouple to P0_4 and P0_5 and trying to display temerature on the LCD.  

My following code works but conversions are incorrect. Why microvolt to temperature routine is giving me in correct results?

 

void main(void)

{

    /* Variable to hold ADC count */

    int32 voltCount = 0;

    int32 microVolts;

    int32 temp1;

    /* Character array to hold the micro volts*/

    char displayStr[15] = {'\0'}; 

    CYGlobalIntEnable; 

    /* Start ADC and start conversion */

    ADC_Start();

    ADC_StartConvert();

    /* Start LCD and set position */

    LCD_Start();

    LCD_Position(0,1);

    LCD_PrintString("ADC Data");

 

    while(1)

    {

        /* Read ADC count and convert to milli volts */

        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);

        voltCount = ADC_GetResult32();

        microVolts = ADC_CountsTo_uVolts(voltCount);

        temp1=Thermocouple_GetTemperature(microVolts);

        sprintf(displayStr," %ld ",temp1);

            LCD_Position(1,0);

            LCD_PrintString(displayStr);

            CyDelay(500);

    }

}



Re: PSoC 5 C functions list and examples

danaaknight posted on 09 Dec 2012 02:04 PM PST
Top Contributor
1773 Forum Posts

Yhe typing for pin registers seems to convery the need for an underscore -

PRTx_PCy[3:1]
PRTx_DMy[7:0]
PRTx_BIE[7:0]

 

From the TRM -

 

1.3.202 PRT[0..11].DM[0..2]
Port Drive Mode Register
Address = (0x40005100 + [0..11 * 0x10]) + 0x2 + [0..2 * 0x1]
Reset: System reset for retention flops [reset_all_retention]
Register : Address
PRT0_DM0: 0x40005102 PRT0_DM1: 0x40005103
PRT0_DM2: 0x40005104 PRT1_DM0: 0x40005112
PRT1_DM1: 0x40005113 PRT1_DM2: 0x40005114
PRT2_DM0: 0x40005122 PRT2_DM1: 0x40005123
PRT2_DM2: 0x40005124 PRT3_DM0: 0x40005132
PRT3_DM1: 0x40005133 PRT3_DM2: 0x40005134
PRT4_DM0: 0x40005142 PRT4_DM1: 0x40005143
PRT4_DM2: 0x40005144 PRT5_DM0: 0x40005152
PRT5_DM1: 0x40005153 PRT5_DM2: 0x40005154
PRT6_DM0: 0x40005162 PRT6_DM1: 0x40005163
PRT6_DM2: 0x40005164

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

danaaknight posted on 09 Dec 2012 02:56 PM PST
Top Contributor
1773 Forum Posts

I noticed on web site ap note is under review, maybe an error in

API's ? In fact no project is there for download.

 

This application note is temporarily unavailable

The document AN66477 - PSoC® 3 and PSoC 5 Temperature Measurement with Thermistor is currently being reviewed and updated to support the new Thermistor Component available in PSoC Creator 2.1. The updated application note is expected by 11/30/2012. The below abstract describes what this application note covers. If you have an immediate need for this document, please click here to create a technical support case requesting this material.

 

Maybe contact autor, yara@cypress.com, to see what issue is.

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

danaaknight posted on 09 Dec 2012 02:59 PM PST
Top Contributor
1773 Forum Posts

Looks like I was not paying attention, you are using a Thermocouple.

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

Tariq posted on 14 Dec 2012 10:17 AM PST
Member
7 Forum Posts

 Hi Dana

 

I do not think underscroes are the issue. See attached file. I get more errors when I added underscores.

 

tariq



Re: PSoC 5 C functions list and examples

Bob Marlowe posted on 14 Dec 2012 12:27 PM PST
Top Contributor
1768 Forum Posts

We are guessing into white mist due to too few information from you..

My guess: you do not have a port in your schematic, so there are no port-registers

 

Will you please upload your project here. To do so: in Creator File -> Create Workspace Bundle(minimal) and then upload the resulting archive here.

 

Bob



Re: PSoC 5 C functions list and examples

danaaknight posted on 14 Dec 2012 05:09 PM PST
Top Contributor
1773 Forum Posts

These are port, onchip, config registers. So look at Cypins defines, and/or

do a search on item with and w/o underscore.

 

Bob is right, upload a project, or an extraction of a project, for forum to examine.

 

Regards, Dana.



Re: PSoC 5 C functions list and examples

Tariq posted on 16 Dec 2012 10:49 AM PST
Member
7 Forum Posts

 Here is a copy of my another example. I am using a PGA block with gain set to 8 before adc. I am not setting gain in the c code since it is already defined in the block.  This code works fine but my issue is the incorrect  values.  I alway get an about 0.1V error.  Measured voltage is always more than the actual applied voltage.  Why?  Where in the mistake? thanks.

 

#include <device.h>
#include "stdio.h"
void main(void)
{
    /* Variable to hold ADC count */
    int16 voltCount, mv;
    /* Character array to hold the volts*/
    /* Amplifier internal gain set to 8 */
    char displayStr[10] = {'\0'}; 
    CYGlobalIntEnable; 
    /* Start ADC and start conversion */
    ADC_Start();
    ADC_StartConvert();
    PGA_Start(); /* start amplifies */
    /* Start LCD and set position */
    LCD_Start();
    LCD_Position(0,1);
    LCD_PrintString("ADC mV Data");
    while(1)
    {
        /* Read ADC count and convert to milli volts */
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
        voltCount = ADC_GetResult16();
        mv=ADC_CountsTo_mVolts(voltCount);
        sprintf(displayStr," %d ",mv);
            LCD_Position(1,0);
            LCD_PrintString(displayStr);
            CyDelay(50);
    }
}

 

 

 



Re: PSoC 5 C functions list and examples

Tariq posted on 16 Dec 2012 11:05 AM PST
Member
7 Forum Posts

 Attached is a copy of my code. I am trying to configure ports and write directly to a port. ( I have LEDs connected to port 0) There is no connection diagram since there is nothing to connect. If I add output pins/port it generate errors that pins/port are not connected. So I am not using any output pins / port.

So far I cannot find useful information on how to configure and write directly to a port. Thanks  Tariq

 



Re: PSoC 5 C functions list and examples

Bob Marlowe posted on 16 Dec 2012 01:19 PM PST
Top Contributor
1768 Forum Posts

Yes, as I thought, you will be surprised by the way you may work with PSoCs. Without a sole change of code you can switch from port0 to port1. I built an example with annotation terminals. Have a look at the definition of the LEDs-pins.

 

Happy coding

Bob



Re: PSoC 5 C functions list and examples

Bob Marlowe posted on 16 Dec 2012 01:21 PM PST
Top Contributor
1768 Forum Posts

By the way... The errors you got when using ports are avoided when de-checking "Hardware Connection" in the properties dialog of the pins.

 

Bob






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