Code Examples Forum Discussions
In the discussion below,
下記のスレッドで
I suggested to see my CY8CKIT-059 version of this program
CY8CKIT-059 版のこのプログラムを参照していただくようにレスしました。
But as the intention of this program was to show basic usage of peripherals for those new to PSoC,
I regret that pointing a project which requires device change and pin assignments change.
So trying to be nicer, I ported this to CY8CKIT-050 (CY8C5868AXI-LP035).
しかし、元々初めて PSoC を使う人に基本的なペリフェラルの使用方法をお見せするという
このプログラムの意図からすると、基板が異なり、デバイスとピンアサインを変更しなくては
行けないプロジェクトをお知らせするのは不親切だったなと壁に向かって反省しました。
というわけで、CY8CKIT-050 (CY8C5868AXI-LP035) に移植したのがこのバージョンです。
Then the bad news is that I'm not be able to afford time to write usage of this program again,
so please refer to the CY8CKIT-059 version for the usage.
さて、悪い知らせとしては、このプログラムの使用方法を再度書く時間がなさそうですので、
下記の CY8CKIT-059 版での使用方法をご参照ください。
The good news is that CY8CKIT-050 has more parts mounted,
so you can use
on board POT for the input of ADC,
pwm output is connected to LED (P6[3])
gpio input is SW2 (P6[1])
gpio output is LED (P6[2])
UART is assigned to P12[6] (rx) P12[7] tx
一方、良い知らせとしては、CY8CKIT-050 には CY8CKIT-059 よりも沢山の部品が搭載されていますので
ADC 入力としては基板上の POT
PWM の出力には LED (P6[3])
GPIO 入力としては SW2 (P6[1])
GPIO 出力としては LED(P6[2])
が使えるようになっています。
また、UART は P12[6] (rx) P12[7] (tx) に割り当ててあります。
moto
Show Less
Hi,
There has been a question (request?) of RC5 IR remote receiver.
https://community.cypress.com/t5/PSoC-4-MCU/IR-interfacing-with-Capsense-Button/m-p/272229#M39274
And by googling the web I found many reference information such as
https://techdocs.altium.com/display/FPGA/Philips+RC5+Infrared+Transmission+Protocol
Then what I noticed was that the standard is usually not in use in Japan,
anyway as I don't watch TV so I don't have a remote control handy 😜
To make and test the receiver, I also needed an emulator of the remote control >_<
So I created an RC5 remote control emulator on CY8CKIT-044 and a sample receiver on CY8CKIT-042.
On CY8CKIT-044 (RC5 Remote Emulator),
when I typed 0 5 53 (which is toggle = 0, address = 5, command = 53 (35h)) similar to the reference site
the waveform on my oscilloscope seemed to be OK.
Note: I emulated the output signal of IRM-36xx, not the real IR light.
Probably if I AND this signal with the carry pulse, IR light like signal could be generated,
but I did not go that far.
Then I connected CY8CKIT-042 and CY8CKIT-044 using
GND-GND
P0[1] - P0[1]
And when I typed below in the Tera Term connected to CY8CKIT-044 (remote control)
CY8CKIT-044 (RC5 remote control emulator)
CY8CKIT-042 (receiver) showed
So they seem to communicate OK.
CY8CKIT-044 (RC5 remote control emulator)
schematic
pins
main.c
============================
#include "project.h"
#include "stdio.h"
#include "tty_utils.h"
#define RC5_ONE 0x01
#define RC5_ZERO 0x02
#define RC5_CLK_PER_BIT 2
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
ShiftReg_Init() ;
tty_init() ;
}
void print_data(uint32_t data)
{
uint32_t mask = (0x01 << 27) ; /* 14 x 2 x halfbits */
while(mask) {
if (mask & data) {
print("1") ;
} else {
print("0") ;
}
mask >>= 1 ;
}
print("\n") ;
}
void send_ir(int toggle, int address, int command)
{
uint32_t data = 0x16 ; /* 010110 */
uint32_t mask ;
// Start Bit 1
data = RC5_ONE ;
// Start Bit 2
data <<= RC5_CLK_PER_BIT ;
data |= RC5_ONE ;
// Toggle Bit
data <<= RC5_CLK_PER_BIT ;
if (toggle) {
data |= RC5_ONE ;
} else {
data |= RC5_ZERO ;
}
/* address 5bit */
mask = 0x10 ; /* 1 0000 */
while(mask) {
data <<= RC5_CLK_PER_BIT ;
if (address & mask) {
data |= RC5_ONE ;
} else {
data |= RC5_ZERO ;
}
mask >>= 1 ;
}
/* command 6bit */
mask = 0x20 ; /* 10 0000 */
while(mask) {
data <<= RC5_CLK_PER_BIT ;
if (command & mask) {
data |= RC5_ONE ;
} else {
data |= RC5_ZERO ;
}
mask >>= 1 ;
}
print_data(data) ;
ShiftReg_Stop() ;
ShiftReg_WriteRegValue(data) ;
ShiftReg_Enable() ;
}
int main(void)
{
int ir_address = 0 ;
int ir_command = 0 ;
int ir_toggle = 0 ;
init_hardware() ;
splash("IR Remote Emulator") ;
print("Enter toggle(0/1) address(5bit) command(6bit)\n\r") ;
prompt() ;
for(;;)
{
if (get_line()) {
sscanf(str, "%d %d %d", &ir_toggle, &ir_address, &ir_command) ;
snprintf(str, STR_BUF_LEN, "toggle: %d address: %d command: %d\n\r", ir_toggle, ir_address, ir_command) ;
print(str) ;
send_ir(ir_toggle, ir_address, ir_command) ;
prompt() ;
}
}
}
============================
CY8CKIT-042 (receiver)
schematic
pins
main.c
========================
#include "project.h"
#include "stdio.h"
#include "tty_utils.h"
#define IR_ST_IDLE 0
#define IR_ST_START_BIT 1
#define IR_ST_TOGGLE 2
#define IR_ST_ADDRESS 3
#define IR_ST_COMMAND 4
#define IR_ST_DATA_READY 5
#define IR_ADDRESS_WIDTH 5
#define IR_COMMAND_WIDTH 6
volatile int ir_status = IR_ST_IDLE ;
volatile int ir_address_bit = 0 ; /* 5bit */
volatile int ir_command_bit = 0 ; /* 6bit */
volatile int ir_toggle = 0 ;
volatile int ir_address = 0 ;
volatile int ir_command = 0 ;
CY_ISR_PROTO(timer_isr) ;
CY_ISR(ir_isr)
{
isr_ir_ClearPending() ;
if (ir_status == IR_ST_IDLE) {
ir_status = IR_ST_START_BIT ;
isr_ir_Disable() ;
isr_ir_ClearPending() ;
isr_bit_ClearPending() ;
isr_bit_StartEx(timer_isr) ;
bit_timer_ClearInterrupt(bit_timer_INTR_MASK_CC_MATCH) ;
bit_timer_Enable() ;
}
}
CY_ISR(timer_isr)
{
int ir_in ;
bit_timer_ClearInterrupt(bit_timer_INTR_MASK_CC_MATCH) ;
ir_in = IR_input_Read() ;
switch(ir_status) {
case IR_ST_IDLE: // should not come here
break ;
case IR_ST_START_BIT:
if (ir_in == 1) {
ir_status = IR_ST_TOGGLE ;
} else {
ir_status = IR_ST_IDLE ;
}
break ;
case IR_ST_TOGGLE:
ir_toggle = ir_in ;
ir_status = IR_ST_ADDRESS ;
break ;
case IR_ST_ADDRESS:
ir_address <<= 1 ;
ir_address |= ir_in ;
if (++ir_address_bit >= IR_ADDRESS_WIDTH) {
ir_status = IR_ST_COMMAND ;
}
break ;
case IR_ST_COMMAND:
ir_command <<= 1 ;
ir_command |= ir_in ;
if (++ir_command_bit >= IR_COMMAND_WIDTH) {
ir_status = IR_ST_DATA_READY ;
isr_bit_Disable() ;
isr_bit_ClearPending() ;
bit_timer_Stop() ;
}
break ;
case IR_ST_DATA_READY: // should not come here
default: // should not come here
break ;
}
}
void clear_data(void)
{
ir_toggle = 0 ;
ir_address = 0 ;
ir_address_bit = 0 ;
ir_command = 0 ;
ir_command_bit = 0 ;
}
void init_hardware(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
tty_init() ;
splash("RC5 Test") ;
isr_ir_ClearPending() ;
isr_ir_StartEx(ir_isr) ;
isr_bit_ClearPending() ;
isr_bit_StartEx(timer_isr) ;
bit_timer_Init() ;
}
int main(void)
{
init_hardware() ;
for(;;)
{
if (ir_status == IR_ST_DATA_READY) {
snprintf(str, STR_BUF_LEN, "toggle: %d address %d: command %d\n\r",
ir_toggle, ir_address, ir_command) ;
print(str) ;
clear_data() ;
ir_status = IR_ST_IDLE ;
isr_ir_ClearPending() ;
isr_ir_StartEx(ir_isr) ;
// isr_ir_Enable() ;
}
}
}
========================
Well, let me call it a day 😉
moto
Show Less
Hello everyone,
I am sharing a project that shows a basic example of how we can use the SCB UART block to wake up the PSoC 4 from DeepSleep mode. I have seen multiple examples of using the I2C for waking up PSoC 4 from DeepSleep. The example with UART is a useful one that can be used in various projects.
Kit used: CY8CKIT-145-40XX PSoC 4000S Prototyping Kit (Link)
Softwares used: PSoC Creator 4.4, Tera Term
Documents referred: PSoC 4 Serial Communication Block (SCB) Component Datasheet (Link)
Method:
- Select an empty project
- In the TopDesign add the UART component (Make sure it is SCB version of UART not UDB)
- Mark the option “Enable wakeup from Deep Sleep Mode” in the configuration window option for the UART SCB block component
- I have attached the screenshot of what configuration I have done for the UART
- Also, add a Digital Output pin in the TopDesign which will be used in connecting an LED that will indicate in which mode PSoC 4 is currently in.
- The next step of the project is the Pin Assignment
- Attaching the screenshot of my pin assignment for the project attached. You may change it according to the board used by you
Code:
int main(void)
{
CyGlobalIntEnable;
UART_Start();
for(;;)
{
LED_Write(0); CyDelay(100);
LED_Write(1); CyDelay(100);
LED_Write(0); CyDelay(100);
LED_Write(1); CyDelay(100);
LED_Write(0); CyDelay(100);
LED_Write(1); CyDelay(100);
UART_Sleep(); // required to be used to use the feature of UART to wakeup the device from DeepSleep
CySysPmDeepSleep();
UART_Wakeup();
}
}
Observations:
The program is written such that the LED will remain off in the deep sleep mode but when the device enters the active mode it will blink 3 times after which the device enters the deep sleep mode again.
After configuring any terminal software(I have used Tera Term) you can connect to the PSoC kit with UART. After which entering any character which will make the device Wakeup from the DeepSleep mode. Thus any character entered in the terminal will lead to the LED getting blicked 3 times.
Attaching the project here
Thanks and regards,
Ronak H
Show Less
Hi,
Provided below is custom implementation of the button switch debouncer component (ButtonSw32). The component uses vertical stack counters algorithm to detect button pressed and released events, and can simultaneously process up to 32 switches without loss of performance.
Component can be useful whenever a simple button switch event need to be detected by PSoC with high reliability, such as control switches, panel-mounted momentary buttons, mechanical joysticks, etc. Component is useful when PSoC hardware debouncing is not justified for handling simple switch button, or for a system with limited hardware resources, such as PSoC4.
The component was tested using CY8KIT-059 PSoC5 prototyping kit and CY8KIT-042 PSoC4 Pioneer Board. Several demo projects are provided alongside the Application Note.
Component major features:
Implements vertical counters algorithm.
Detects button pressed and released events.
Detects simultaneously up to 32 buttons.
Does not consume hardware resources.
Attached archive contains component library, component datasheet and several demo projects for PSoC5 and PSoC4. Please read installation instructions in the readme.txt.
The component provided as-is, no liabilities. It is free to use and modify.
regards,
odissey1
=============================================================================
=============================================================================
P.S. Another useful component for HMI can be found here:
Quad Decoder with Button Switch component for rotary shaft encoders
Show Less
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