Reading 16 GPIO pins "atomically"

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

cross mob
RiTa_288331
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted

Using the PSOC6 Pioneer kit, it is interfaced with an external ADC (16 bit parallel output).

I have the 16 GPIO pins configured, but they are spread across several ports of the Pioneer kit (ports 0, 1, and 5).

When reading these 16 bits, is there a "fast read", or a way of reading all 16 GPIO pins at once, in order to save time?

0 Likes
1 Solution
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

RiTa,

There is related discussion re writing 16-bit value atomically to 2 Control registers in PSoC5. Same approach may work for PSoC6

Can be expanded control register component to 16bit or 32bit? (That meaning is not to use two contro...

32-bit parallel non-contiguous GPIO write technique

/odissey1

View solution in original post

2 Replies
RiTa_288331
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted

Just a quick addition, here is my code to read the 16 pins, scattered across multiple ports:

resultADC = (Cy_GPIO_Read(P11_0_PORT, P11_0_NUM)) |

                    (Cy_GPIO_Read(P11_2_PORT, P11_2_NUM) << 1) |                                                      

                    (Cy_GPIO_Read(P7_0_PORT, P7_0_NUM) << 2) |                                                      

                    (Cy_GPIO_Read(P7_3_PORT, P7_3_NUM) << 3) |                   

                    (Cy_GPIO_Read(P7_4_PORT, P7_4_NUM) << 4) |                                                      

                    (Cy_GPIO_Read(P7_5_PORT, P7_5_NUM) << 5) |                                                    

                    (Cy_GPIO_Read(P7_6_PORT, P7_6_NUM) << 6) |                   

                    (Cy_GPIO_Read(P7_7_PORT, P7_7_NUM) << 7) |                                                      

                    (Cy_GPIO_Read(P8_7_PORT, P8_7_NUM) << 😎 |                                                      

                    (Cy_GPIO_Read(P8_6_PORT, P8_6_NUM) << 9) |

                    (Cy_GPIO_Read(P8_5_PORT, P8_5_NUM) << 10) |                                  

                    (Cy_GPIO_Read(P8_4_PORT, P8_4_NUM) << 11) |                                  

                    (Cy_GPIO_Read(P8_3_PORT, P8_3_NUM) << 12) |

                    (Cy_GPIO_Read(P8_2_PORT, P8_2_NUM) << 13) |                                  

                    (Cy_GPIO_Read(P8_1_PORT, P8_1_NUM) << 14) |   

                    (Cy_GPIO_Read(P8_0_PORT, P8_0_NUM) << 15);

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

RiTa,

There is related discussion re writing 16-bit value atomically to 2 Control registers in PSoC5. Same approach may work for PSoC6

Can be expanded control register component to 16bit or 32bit? (That meaning is not to use two contro...

32-bit parallel non-contiguous GPIO write technique

/odissey1