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...
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. 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, P3
Following is an example code to connect P0 to UART Tx
/* First disconnect P3 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 as GPIO. This will disconnect it from UART
/* Connect P0 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
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.
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+P3. 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.
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
Sorry about the formatting; only the viewing window is truncated, you can still copy-paste code to see the full lines.
Can you archive your test project and post the .zip file here? I will take a look.
1 of 1 people found this helpful
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);
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
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!
You are most welcome Steve! Glad that the problem is resolved.