Code Examples Forum Discussions
I've attached a two-project Workspace.
The first project (KitProg_XRES2PwrCycle) is only useful for the TopDesign.
It has the circuit I have used and tested to program PSoCs without an XRES pin. It monitors the XRES pin from the 5-pin programming device and power cycles the VDD to the target CPU.
In addition to power cycling VDD to the target PSoC it also quickly discharges the capacitor on the VDD line with about 2.2 ohms to GND.
It is a single-IC design with a KitProg (5-pin) programming header, a 5-pin Target programming header and a 3-pin jumper for bypassing the VDD power cycling if needed.
I placed the single-IC and headers and jumper on a very small proto board as displayed in the TopDesign.
The second project is an example very simple project using the CY8C4013 PSoC which has no XRES. It programs the SWD pins as GPIO to test the programmability of the PSoC.
In general, I recommend using a PSoC with a XRES pin routed to the programming header. In this case, this power cycling circuit is not needed but still be used.
However, if this isn't an option for you, this is a small form factor and very simple HW project.
Enjoy!
Show LessHi,
I have just posted this to a discussion below for a possible solution.
But as this could be useful when you have used up all UART components and you need yet another UART TX,
I'm posting this here, too.
schematic
pins (or "a pin" ?)
main.c
#include "project.h"
#include "stdio.h"
#define STR_BUF_LEN 64
#define BIT_DELAY_US 104 /* 9600Hz -> 104.17us */
void soft_tx_send_byte(uint8_t data)
{
uint8_t mask = 0x01 ;
int i ;
soft_tx_Write(1) ; /* make sure that the level is high */
CyDelayUs(BIT_DELAY_US * 2) ;
soft_tx_Write(0) ; /* generate start bit */
CyDelayUs(BIT_DELAY_US) ;
for (i = 0; i < 8; i++ ) {
if (mask & data) {
soft_tx_Write(1) ;
} else {
soft_tx_Write(0) ;
}
mask <<= 1 ;
CyDelayUs(BIT_DELAY_US) ;
}
soft_tx_Write(1) ; /* generate stop bit */
CyDelayUs(BIT_DELAY_US * 2) ;
}
void soft_tx_send_string(char *str)
{
while(str && *str) {
soft_tx_send_byte(*str++) ;
}
}
int main(void)
{
char str[STR_BUF_LEN+1] ;
int count = 0 ;
CyGlobalIntEnable; /* Enable global interrupts. */
soft_tx_send_string("\x1b[2J\x1b[;H") ;
soft_tx_send_string("Test Software UART TX ") ;
snprintf(str, STR_BUF_LEN, "(%s %s)\n\r", __DATE__, __TIME__) ;
soft_tx_send_string(str) ;
for(;;) {
snprintf(str, STR_BUF_LEN, "count %d\n\r", count++) ;
soft_tx_send_string(str) ;
CyDelay(1000) ;
}
}
Tera Term log
moto
Show Less
Hello,
If you evaluate UART reception error for example frame error and parity error, use this sample project.
When you send data from the terminal software of your PC, the sent data will be echoed back. Then, the sent data is output with the set baud rate, parity, and stop bit length.
It is also possible to change the polarity of the stop bit to generate an error.
To enable 230400bps, make the following settings.
The baud rate of the Pseudo UART is set by the timer Period.
You can change the polarity and bit length of the stop bit, none, even, odd of parity on the line with # in the comment in main.c.
Best regards,
Yocchi
Show LessHello,
I was approached by someone who required to use the PC's BLE instead of Uart serial to output PSoC logs and data. And since there was no sample, I made one.
The environment used is as follows:
・PSoC Creator 4.2
・CY8CKIT-062-BLE
In the case of Bluetooth, we were able to use SPP to represent it, but BLE does not have this profile, so we need to create a custom one. The communication between the PSoC6 kits was created by Yugandhar, so I used this Peripheral side program as a base and combined it with a simple printf sample. When the SW2 on the kit is pressed, a message is counted up and displayed on PC’s DOS window.
The program using BLE on the PC side has been created in C#/VisualStudio2019 and can be used as a basic program for PC BLE. It runs on the DOS of the PC and can pair with BLE devices and read/write, but in this case, we have chosen to run read directly after pairing. The menu is not shown in the comment out, but you can select Read or Write as well.
After the PSoC side program is executed, the PC side program is executed on Dos. The procedure is:
- Scanning for BLE Devices
- Connect to the PSoC 6 BLE kit
- Press SW2 on the PSoC 6 BLE Kit and verify that the message on the DOS updates.
The PC I am using is Win10 with BLE4.2. The result is displayed as follows:
C:\Users\134546\source\repos\BLE_Dice\bin\Debug>BLE_Dice.exe BLE Gatt Client(.Net Framework) by Marubun
Menu: 1:Scan 2:Connect Q:Exit ? 1
Scan Start ---Received--- MAC:00A050AABBFF <- PSoC6's NAME:BLE_Serial ---Received--- MAC:12AA042E349B NAME: -------------- Scan Stop
Menu: 1:Scan 2:Connect Q:Exit ? 2
0:00A050AABBFF <- PSoC6's 1:12AA042E349B ? 0
Connect to 00A050AABBFF UART Service {0x0003cdd0,0x0000,0x1000,{0x80,0x00,0x00,0x80,0x5f,0x9b,0x01,0x31}} found RXD Char. {0x0003cdd2,0x0000,0x1000,{0x80,0x00,0x00,0x80,0x5f,0x9b,0x01,0x31}} found TXD Char. {0x0003cdd1,0x0000,0x1000,{0x80,0x00,0x00,0x80,0x5f,0x9b,0x01,0x31}} found Notification Enabled Connect success
Menu: 1:Scan 2:Connect Q:Exit ? Please start PSoC. <- Push SW2 on 062 kit Hello Count 1 Hello Count 2 Hello Count 3 Hello Count 4 Hello Count 5 Hello Count 7 Hello Count 8 : |
Known issue:
As mentioned above, the first column is missing for some reason. So I put a blank in the first column of the message, but I hope someone will fix this bug and post it.
Thanks,
Kenshow
Hello,
I have prepared a sample project for interrupt processing from GPIO pins of the same port group.
This is based on "7.8 Pin Interrupt" in AN86439.
GPIO interrupts are possible from P0.2 and P0.3. This method will result in an error when building if the port numbers are not consecutive. For example, it cannot be set to P0.2 and P0.4. Since the IRQ is the same in the same port group, the same interrupt handler is used. Therefore, for example, the handler contains a judgment as to whether or not a P0.3 interrupt occurred during interrupt processing by P0.2.
Unfortunately, Pin_P0_ClearInterrupt () clears the pending interrupt bit of all bits, so any interrupts from other pins between the following will be ignored. It is necessary to devise such as adding the pin input to the judgment.
while((uint8)Pin_P0_INTSTAT != intstatus_flag)
{ ...}
**If an interrupt on another pin occurs during this time, it will be ignored.**
Pin_P0_ClearInterrupt();
[Method of operation]
- Connect two tact switches as shown below.
- When you press SW3, LED4 lights up for 1 second. And when you press SW4, LED5 lights up for 1 second.
If you press one of the SWs and press the other SW while it is lit for 1 second, two SWs will be processed in one interrupt handler, and LED6 will be lit.
Best regards,
Yocchi
Show LessHello,
You need the following code to stop TCPWM, enter DeepSleep, then wake up with the wakeup event and restart TCPWM.
PWM_Sleep();
CySysPmDeepSleep();
PWM_Wakeup();
However, if you use CY8CKIT-145-40XX to blink LED4 (P2_0) with PWM and set it to DeepSleep, you can see that the DeepSleep current is large. If you do the following, the Deep Sleep current will be the specified value.
PWM_Sleep();
Pin_LED4_SetDriveMode(Pin_LED4_DM_ALG_HIZ);
CySysPmDeepSleep();
Pin_LED4_SetDriveMode(Pin_LED4_DM_STRONG);
PWM_Wakeup();
Alternatively, in the case of LED4 (P2_0), the above cord may not be necessary if a pull-up resistor is connected externally.
[Preparation for operation]
You need to prepare a tact switch and add it to P0_0 to connect.
[How to operate this project]
When you program and press SW1 (RST), LED4 (P2_0) is blinking.
1. You can push SW2 (P0_7) to stop TCPWM and put it in the Deep Sleep state.
2.It wakes up by pressing the tact switch (P0_0). And TCPWM will start working.
Best regards,
Yocchi
Show Less
Hello,
This is a sample code for wakeup from DeepSleep using UART for CY8CKIT-145-40XX.
You need to have 4 pull-up resistors shown in blue wiring.
[How to operate]
Set the terminal software of your PC as follows.
- Into DeepSleep mode
If you send data with the terminal software after pressing SW2, it will be in Deep Sleep mode.
- Wake up from DeepSleep mode
It wakes up when you send data from the terminal software while in DeepSleep mode.
Unfortunately, the data received for wakup is unreliable.
Please see the wake up time TDEEPSLEEP in "PSoC 4 Serial Communication Block (SCB)" datasheet.
for example:
parity:none
send data -> recieved data
0x11 0xf1
0x32 0x99
0x00 0xff
0xff 0xff
parity:even
send data -> recieved data
0xff 0x7f
note:
Since the communication settings of KitProg3 are as follows, it is not possible to send and receive by setting parity.
Best regards,
Yocchi
Show LessHello,
This is a sample code for wakeup from DeepSleep using UART for CY8CKIT-145-40XX.
However, it is woken up by GPIO interrupt.
You need to have 4 pull-up resistors shown in blue wiring.
[How to operate]
Set the terminal software of your PC as follows.
- Into DeepSleep mode
If you send data with the terminal software after pressing SW2, it will be in Deep Sleep mode.
- Wake up from DeepSleep mode
It wakes up when you send data from the terminal software while in DeepSleep mode.
When 0x00 data is received, it wakes up, but the data does not enter the receive buffer.
When it receives anything other than 0x00 data, it wakes up, but the data in the receive buffer is unreliable.
Best regards,
Yocchi
Show LessHi,
This is a simple sample of using CapSense [v7.0] for 2 buttons operation using CY8CKIT-042.
Although this is a quite simple sample, may be somewhat useful for those who is not familiar with writing C program(s),
such as the discussion below.
I assigned the node P1.5 as "Up" button and P1.1 as "Down" button.
schematic
CapSense Config
Pins
Since I don't have many LEDs on my CY8CKIT-042,
I let UART write "*" instead of LEDs.
main.c
==========================
#include "project.h"
#include "stdio.h"
#define MAX_LED_COUNT 4
#define MIN_LED_COUNT 0
#define STR_BUF_LEN 32
char str[STR_BUF_LEN+1] ;
void print(char *str)
{
UART_PutString(str) ;
}
void cls(void)
{
print("\x1b[2J\x1b[;H") ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
cls() ;
CapSense_Start() ;
CapSense_ScanAllWidgets() ;
}
void do_led(int led_count)
{
switch(led_count) {
case 0: /* MIN_LED_COUNT? */
/* turn off all LEDs */
cls() ;
break ;
case 1:
/* turn on only 1 LED */
cls() ;
print("*\n\r") ;
break ;
case 2:
/* turn on 2 LEDs */
cls() ;
print("* *\n\r") ;
break ;
case 3:
/* turn on 3 LEDs */
cls() ;
print("* * *\n\r") ;
break ;
case 4: /* MAX_LED_COUNT? */
/* turn on 4 LEDs */
cls() ;
print("* * * *\n\r") ;
break ;
default:
/* do nothing */
break ;
}
}
int main(void)
{
int led_count = 0 ;
init_hardware() ;
for(;;)
{
if (CapSense_NOT_BUSY == CapSense_IsBusy()) {
CapSense_ProcessAllWidgets() ;
if (CapSense_IsAnyWidgetActive()) {
if (CapSense_IsSensorActive(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS0_ID)) {
led_count++ ;
if (led_count > MAX_LED_COUNT) {
led_count = MAX_LED_COUNT ;
}
} else if (CapSense_IsSensorActive(CapSense_BUTTON0_WDGT_ID, CapSense_BUTTON0_SNS1_ID)) {
led_count-- ;
if (led_count < MIN_LED_COUNT) {
led_count = MIN_LED_COUNT ;
}
}
do_led(led_count) ;
}
CyDelay(100) ;
CapSense_ScanAllWidgets() ;
}
}
}
==========================
moto
Show Less
A week or so ago, I posted a sample of directly handling 1602 charLCD.
But there also was a request for a sample using an I2C-LCD module.
So I ordered my modules to Amazon, then noticed that there were very few documentation(s) available for the module,
except Arduino C++ sample.
At first I tried to port the Arduino sample, but the more I tried the more screwed up I was 😜
Today, I realized that the device on the module is PCF8574, which is an I2C - port expander and reading the datasheet it's pretty easy to handle. So I discarded my pasta I've been boiled for a few days and ported my previous program directly using the PCF8574.
Anyway, it seems to be working now.
Schematic
Note: Using the module (and/or CY8CKIT-062-BLE) we don't need external I2C pull-ups.
Although the spec of the I2C module was 5V, it worked OK with 3.3V on my side of the planet.
If you are going to use 5V LCD module and power the I2C-LCD module with 5V,
please use 3.3V for I2C pull up to avoid burning PSoC 6.
(You may need to remove 4.7K pull-ups on the module, which is connected to VCC (=5V))
Pins
Tera Term log (to write "Hello World!" from this program)
moto
[Edit] 12-Mar-2021 fixed a type
Show Less