6 Replies Latest reply on Aug 16, 2012 2:51 PM by user_27941315

    PSoc _read() query

    cathal.ferry

      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

        • 1. Re: PSoc _read() query
          arvi

           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!

          • 2. Re: PSoc _read() query
            user_14586677

            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

            • 3. Re: PSoc _read() query
              user_14586677

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

                 

               

                 

              Regards, Dana.

              • 4. Re: PSoc _read() query
                arvi

                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;  

                • 5. Re: PSoc _read() query
                  cathal.ferry

                  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

                  • 6. Re: PSoc _read() query
                    user_27941315

                    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.