Writing to Digital outputs as bus

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

cross mob
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

Hi,

I have 8 digital outputs that are on various pins of the 5LP that I want to control as a port using an 8-bit variable in code.

I created a digital output pin then then set number of pins to 8. I named the port "POWER"

Next I selected "Display as Bus" mapping.

Then I went to "pins" tab and set the pin designation.

I am having trouble setting the value of "PORT" in code.

The intellisense in PSOC creator shows "POWER_0, POWER_1 etc but I cannot work out correct syntax to do equivalent of POWER_Write(23) for instance.

Have I set this up wrong or simply not using corect syntax?

Thanks

0 Likes
1 Solution
BiBi_1928986
Level 7
Level 7
First comment on blog 500 replies posted 250 replies posted

Hello DaHu.

The example by Moto is perfect when you have an entire 8-bit port available.

When you have random GPIO's from several ports, you can use the Control_Reg component.  Now you can connect just about any GPIO output pin to the Control Reg output signal.

To write to this component is very simple.

Control_Reg_1_Write(i);    /* where i is uint8 */

pastedImage_0.png

This is not a bidirectional solution.  It is for writing only to the GPIO's.

Good luck with your project.

View solution in original post

3 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

That is an interesting question!

Although I knew that we can have a pin displayed as a bus,

I have never tried write/read as a bus.

So I used my CY8CKIT-059 and used P3[7:0] as an 8-bit bus.

schematic

002-schematic.JPG

POWER pin configuration

004-POWER_Pins.JPG

005-POWER_Mapping.JPG

Pins

003-Pins.JPG

main.c

====================

#include "project.h"

#include "stdio.h"

#define STR_BUF_LEN 64

char str[STR_BUF_LEN+1] ;

void print(char *str)

{

    UART_PutString(str) ;

}

int main(void)

{

    int i, data ;

   

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

    for(;;)

    {

        for (i = 0 ; i < 0x100 ; i++ ) {

            POWER_Write(i) ;

            CyDelay(500) ;

            data = POWER_Read() ;

            snprintf(str, STR_BUF_LEN, "%d\n\r", data) ;

            print(str) ;

            CyDelay(500) ;

        }

    }

}

====================

Tera Term log

001-TeraTerm-log.JPG

So as far as setting pins in a port as a bus, it seems to be working.

moto

BiBi_1928986
Level 7
Level 7
First comment on blog 500 replies posted 250 replies posted

Hello DaHu.

The example by Moto is perfect when you have an entire 8-bit port available.

When you have random GPIO's from several ports, you can use the Control_Reg component.  Now you can connect just about any GPIO output pin to the Control Reg output signal.

To write to this component is very simple.

Control_Reg_1_Write(i);    /* where i is uint8 */

pastedImage_0.png

This is not a bidirectional solution.  It is for writing only to the GPIO's.

Good luck with your project.

Thanks, that solves the issues nicely

0 Likes