Multiplex single SCB to multiple ports in application?

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

cross mob
Anonymous
Not applicable

On a PSOC 4000s, 2 x SCBs are available. However I have a need for 3 x UART bi-directional interfaces. SCB1 is mappable to 2 different ports (P0, P3), SCB0 to a single port (P4).

   

Is it possible, during run-time in an application, to multiplex SCB1 between P0 and P3? I'm thinking build/synthesis only allows a fixed SCB-to-port mapping, but that would make a world of difference if this can be dynamic!

   

If not possible, I'm open to alternate approaches. UART is not a requirement, slow baud rade is okay (e.g. 9600) but flash memory is tight. SW UART component is Tx only. I feel writing my own Rx or protocol would be a time sink.

   

Thanks!

0 Likes
1 Solution
MR_41
Employee
Employee
First like received

Hi Steve,

   

As I did not have the PSoC4000 board to test your project as it is, I ported it to PSoC4200 which required renaming some constants.  But I was able to reproduce your issue of no characters coming out of Port 3.  The solution is to configure P3_1 as strong drive and initialize it to 1.  Try adding this code in the beginning of your initialization code and let me know if this works.

   


// Configure P3_1 to Strong drive and set it to HIGH
CY_SYS_PINS_SET_DRIVE_MODE(CYREG_GPIO_PRT3_PC, 1, CY_SYS_PINS_DM_STRONG);
CY_SYS_PINS_SET_PIN(CYREG_GPIO_PRT3_PC, 1);
 

   

Best Regards,

   

Ganesh

   

PS: When I was testing with my P4200 board, I observed a very strange problem.  The string "SCB port switched" would print as "SCB" followed by some junk.  I replaced this string with "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" and it was printing this string fine.  This could be some totally unrelated issue though

View solution in original post

9 Replies
Anonymous
Not applicable

Tried to use a copy of auto generated code for SCB1 + cyfitter.h to other port which I wish to multiplex with. Created a design wide clock with the correct name. Although the code compiles and runs, can't get comms to the other port. Bummer :(, was really hoping this would work...

0 Likes
MR_41
Employee
Employee
First like received


You should be able to do this switching using HSIOM_PORT_SELx register.

   

 
HSIOM_PORT_SELx register controls which mapped peripheral drives a particular port pin.  Each port has a HSIOM_PORT_SEL register, with 4 bits representing each port pin.  For example, Bit#0 to Bit#3 of HSIOM_PORT_SEL0 register control the connection for P0[0].  The P4000S register TRM has details of what value is to be written to these bits to connect the pins to various signal sources.  The P4000S device data sheet has a table that lists which pins are mapped to the SCBs.
For example, SCB1 UART_TX can be connected to P0[5], P3[1]
Following is an example code to connect P0[5] to UART Tx

   


/* First disconnect P3[0] from SCB1 UART Tx and make it a GPIO */
TempVal = CY_GET_REG32(CYREG_HSIOM_PORT_SEL3);
TempVal &= ~0x000000F0;  // Clear Bit#4 to Bit#7 to configure P3[1] as GPIO. This will disconnect it from UART
CY_SET_REG32(CYREG_HSIOM_PORT_SEL3, TempVal);

 

   

/* Connect P0[5] to SCB1 UART Tx */
TempVal = CY_GET_REG32(CYREG_HSIOM_PORT_SEL0);
TempVal &= ~0x00F00000; // Clear Bit#20 to Bit#23
TempVal |= 0x00900000; // Write 9 to Bit#20 to Bit#23 which connects pin#5 to UART Tx
CY_SET_REG32(CYREG_HSIOM_PORT_SEL0, TempVal);

   

Note: I have not tested the above code.  I have given the code to explain the concept.  Cross check the values using the Register TRM and device data sheet.
 

0 Likes
Anonymous
Not applicable

Hi graa, thanks for the response. I've used HSIOM for switching in-app between GPIO and SCB modes w/o issue before. However that does not seem to work for switching between a shared SCB. Maybe now is a good time for me to re-read the TRM section on HSIOM 🙂

   

Setup: FTDI adapter attached to P3[0]+P3[1]. Messages print okay when PSOC Creator "pins" GUI has uart_scb1a configured to P3, which shows the port cfg commands should be correct. However when GUI is set to P4, no messages are printed at all.

   

Any thoughts?

   
      uart_scb1a_Start();     CyDelay(100);     uart_scb1a_UartPutString("SCB port initial\r\n");     CyDelay(100);      // Configure HSIOM for P0_4 to GPIO hi-z     CY_SET_REG32(CYREG_HSIOM_PORT_SEL0, ((CY_GET_REG32(CYREG_HSIOM_PORT_SEL0) & ~(HSIOM_PIN4_MASK)) | CYVAL_HSIOM_IO0_SEL_GPIO));     CY_SYS_PINS_SET_DRIVE_MODE(CYREG_GPIO_PRT0_PC, 4, CY_SYS_PINS_DM_DIG_HIZ);      // Configure HSIOM for P0_5 to GPIO hi-z     CY_SET_REG32(CYREG_HSIOM_PORT_SEL0, ((CY_GET_REG32(CYREG_HSIOM_PORT_SEL0) & ~(HSIOM_PIN5_MASK)) | CYVAL_HSIOM_IO0_SEL_GPIO));     CY_SYS_PINS_SET_DRIVE_MODE(CYREG_GPIO_PRT0_PC, 5, CY_SYS_PINS_DM_DIG_HIZ);      // Configure HSIOM for P3_1 to SCB UART     CY_SET_REG32(CYREG_HSIOM_PORT_SEL3, ((CY_GET_REG32(CYREG_HSIOM_PORT_SEL3) & ~(HSIOM_PIN1_MASK)) | (CYVAL_HSIOM_IO0_SEL_ACT_1 << CYFLD_HSIOM_IO1_SEL__OFFSET)));      // Configure HSIOM for P3_0 to SCB UART     CY_SET_REG32(CYREG_HSIOM_PORT_SEL3, ((CY_GET_REG32(CYREG_HSIOM_PORT_SEL3) & ~(HSIOM_PIN0_MASK)) | (CYVAL_HSIOM_IO0_SEL_ACT_1 << CYFLD_HSIOM_IO0_SEL__OFFSET)));       CyDelay(100);     uart_scb1a_UartPutString("SCB port switched\r\n");     CyDelay(100);  ...  // Self defined, all other in cydevice_trm.h  #define HSIOM_PIN0_MASK         0xF #define HSIOM_PIN1_MASK         0xF0 #define HSIOM_PIN4_MASK         0xF0000 #define HSIOM_PIN5_MASK         0xF00000
0 Likes
Anonymous
Not applicable

Sorry about the formatting; only the viewing window is truncated, you can still copy-paste code to see the full lines.

0 Likes
MR_41
Employee
Employee
First like received

Can you archive your test project and post the .zip file here?  I will take a look.

   

 

   

Best Regards,

   

Ganesh

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi Ganesh, I attached a sample project which exhibits the symptom of not switching. Please have a look, thanks for your help.

   

 

   

Steve

0 Likes
MR_41
Employee
Employee
First like received

Hi Steve,

   

As I did not have the PSoC4000 board to test your project as it is, I ported it to PSoC4200 which required renaming some constants.  But I was able to reproduce your issue of no characters coming out of Port 3.  The solution is to configure P3_1 as strong drive and initialize it to 1.  Try adding this code in the beginning of your initialization code and let me know if this works.

   


// Configure P3_1 to Strong drive and set it to HIGH
CY_SYS_PINS_SET_DRIVE_MODE(CYREG_GPIO_PRT3_PC, 1, CY_SYS_PINS_DM_STRONG);
CY_SYS_PINS_SET_PIN(CYREG_GPIO_PRT3_PC, 1);
 

   

Best Regards,

   

Ganesh

   

PS: When I was testing with my P4200 board, I observed a very strange problem.  The string "SCB port switched" would print as "SCB" followed by some junk.  I replaced this string with "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" and it was printing this string fine.  This could be some totally unrelated issue though

Anonymous
Not applicable

This is great Ganesh, although I'm face palming right now because obviously you need to configure the drive mode from default hi-z input before using it! I have a version that just rapidly switches between the two and everything seems to work.

   

On the PSOC 4000s, I don't see any unexpected garbage characters. When rendering on a terminal, I do see a junk character when transitioning between hi-z and strong drive out; this is due to the rise time of the level being slow enough to be unintentionally sampled. However when just leaving it strong drive, the junk char symptom resolves.

   

Thanks again for your help!

0 Likes
MR_41
Employee
Employee
First like received

You are most welcome Steve! Glad that the problem is resolved.

   

Best Regards,

   

Ganesh

0 Likes