Code Examples Forum Discussions
I've attached a custom component that is a TopDesign selectable component for the PSoC5 LPF (low-pass filter) block.
Previously the 2 fixed function LPF blocks available in the PSoC5 were only available by accessing the PSoC5 registers directly. With this component, it can be included, configured (4 corner frequency selections) and routed by PSoC Creator.
This component has a number of run-time APIs to allow for setting a "new" corner frequency and to stop or disable it.
If the component is Stopped or Disabled, the LPF will automatically BYPASS to allow the full frequency spectrum of the input to the output. Re-enabling or starting the LPF will invoke the last corner frequency setting.
Requirements:
- PSoC Creator 4.2 or higher.
- PSoC5 Device Family.
Enjoy,
Len
Show LessHi all,
The electronic dice I posted last time was very popular. So, I add a piezoelectric buzzer to generate sound with PWM. Please refer to the link for details regarding the electronic dice and the piezoelectric buzzer of PWM.
The environment used is as follows:
・PSoC Creator 4.2
・CY8CKIT-062-BLE
The counter of the dice used the timer last time, but I changed it to PWM (PWM_1) because I want to control the length of the sound with Low/High signales. It is PWM_2 that produces the beep sound. PWM_2 used Start and Stop (Kill) inputs to control the blinking of the LED and the duration of the sound. The circuit is as follows:
The period of PWM_1 is set to the same period as the previous timer setting (Period0 = 399: 25Hz). Compare0 is set to 200 as the length of beep.
PWM_2 determines the frequency of the beep. This time, it is set to 2KHz (input clock is 1MHz, Period=499). Compare0 is 200 counts and is fixedly used in the program. The settings are as follows:
In the Advance tab, set Start Input to Rising Edge and Kill Input to Falling Edge to enable Start and Stop (Kill) inputs.
The buzzer pin is set to P12 [0] and the other pins are set as follows:
The program contains the control of PWM_1and 2.
#include "project.h"
uint32_t sw=0; //sw is off (Stop rolling dicce)
int main(void)
{
__enable_irq(); /* Enable global interrupts. */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
Clock_Enable() ;
CapSense_Start();
CapSense_ScanAllWidgets(); // Start Initial Scan
for(;;)
{
if(!CapSense_IsBusy())
{
CapSense_ProcessAllWidgets();
if(sw==0){ // If sw is on, check start botton0.
if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID)) // Check button 0 state
{
/* Start rolling dice*/
PWM_1_SetCounter(0);
PWM_1_SetPeriod0(399);
//PWM_1_SetCompare0(200);
PWM_1_Start(); // Start rolling dice
PWM_2_Start();
sw=1; // sw is on
}
}
if(sw==1){ // If sw is on, check stop botton0.
if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID)) // Check button 1 state
{
/* Roll dice slowly */
PWM_1_SetCounter(0);
PWM_1_SetPeriod0(1999);
//PWM_1_SetCompare0(200);
CyDelay(1500); // keep rolling slowly for 1.5sec
PWM_1_Disable();// Stop rolling dice
PWM_2_Disable();
sw=0; // sw is off
}
}
CapSense_UpdateAllBaselines();
CapSense_ScanAllWidgets(); // Start next scan
}
}
}
Thanks,
Kenshow
Show LessHi.
This sample uses CY8CKIT-044.
I created a stopwatch timer using segmented LEDs.
The LED display is based on the sample in "TSoC CY8C4146LQI-S433 基板 7SEG LED サンプル ".
Start and stop of the stopwatch timer are judged by interrupt from SW2 of CY8CKIT-044.
The LED time is updated every 100 msec.
State Machine of the stopwatch timer is as shown in the figure.
#define STANBY_MODE 0 /* initial state 7SEG LED "0000" */
#define COUNT_STOP_MODE 1 /* Count stop */
#define COUNT_UP_MODE 2 /* Count up */
Thanks,
Asanuma
Show LessHi,
This is a demo of the simple FM transmitter using PSoC5 (KIT-059). The project is very simple and uses no software code. AC input from the audio source is amplified (0-4V) and applied to the varactor diode, which controls frequency of the ceramic resonator (4.19 MHz). PSoC5 PLL is set to operate at 75.4MHz, which is 18x harmonic of the XTAL. It appears that PSoC5 internal PLL lock time is quite short (<250us), so that PLL can track the audio frequency (up to ~5kHz), though it less efficient at high range. Antenna is made from a 2" piece of wire, which is connected directly to the BUS_CLOCK output. There is no tank circuit, so transmitter emits on many harmonics of the main (1x, 3x, 5x...). Fortunately, 75MHz and 226MHz regions are empty, and emitted power is rather low (<100nW) so there is no issues with FCC.
Any other ceramic resonator will work, the 4.19MHz is what i had at hands. PLL will lock to any XTAL with frequency >=4MHz. The varactor is also not specific, look for any which adjusts in 10-100pf in 0-4V range (hyperabrupt type). Since PLL feedback decreases with modulation frequency, adding simple CR high-pass filter at audio input with Fcutoff~1-4kHz improves FM output.
RTL-SDR receiver dongle was used to receive the signal, and SDR# for visualization. See official website for details:
Project archive is attached.
Project uses the Annotation Library for connection diagram: Annotation library for CY8CKIT-059 Prototyping Kit
YouTube video of transmitter action: PSoC5 FM audio transmitter (PSoC, PSoC5LP, PSoC 5) - YouTube
/odissey1
Figure 1. KIT-059 connection diagram using Annotation Library for CY8KIT-059.
Figure 2. Breadboard assembly (standard bredboard is split in two pieces).
Figure 3. RF receiver: RTL-SDR with short wire as an antenna.
Figure 4. RTL-SDR GUI (SDR#) snapshot at 75.581MHz.
Show Less
Attached project shows how to config USBIO to GPIO digital input & output mode in firmware. Project is created based on Creator 4.3 and CY8CKIT-062-WIFI-BT DVK, to run this demo pin USBDP and P13_5 should be shorted by fly wire on DVK first.
In short:
Config USBIO to GPIO digital output, you should:
1) Set USBIO to GPIO mode. Write the USBIO_CR1 register (USBDEV_Regs) to 0x20.
*(uint32 *)CYREG_USBFS0_USBDEV_USBIO_CR1 |= (0x01u << CYFLD_USBFS_USBDEV_IOMODE__OFFSET);
2) Set drive mode of USBIO to Strong output.
Config USBIO to GPIO digital input mode, you should:
1) Set USBIO to GPIO mode. Write the USBIO_CR1 register (USBDEV_Regs) to 0x20.
*(uint32 *)CYREG_USBFS0_USBDEV_USBIO_CR1 |= (0x01u << CYFLD_USBFS_USBDEV_IOMODE__OFFSET);
2) Set GPIO input enable. Write the USBIO_CTL register (USBDEV_LPM_Regs) to 0x09.
*(uint32 *)CYREG_USBFS0_USBLPM_USBIO_CTL |= ((0x01u << CYFLD_USBFS_USBLPM_DM_P__OFFSET) | (0x01u << CYFLD_USBFS_USBLPM_DM_M__OFFSET));
3) Set drive mode of USBIO to Digital HighZ.
Message was edited by: Xiaowei Zhang
Show LessHi,
Although I have posted tty utils before it may not be simple enough to be used.
以前に tty utils をポストしてはいたのですが、簡潔さが不充分と感じたため
Re: tty_utils a utility sample for CLI type program
So I posted a line read sample for PSoC 5LP.
昨夜、UART からの 1行読み込みのサンプルを PSoC 5LP 用に書いてポストしました。
PSoC 5LP Simple Samples for Uart input in char array save
And here is a version for PSoC 4.
で、折角なので PSoC 4 版も作成してみました。
The followings are a version using polling and a version using interrupt.
以下、ポーリング版と割込み利用版です。
(1) Polling Version / ポーリング版
schematic
pins
Tera Term log
main.c
=====================
#include "project.h"
#include "stdio.h"
#define CR '\r'
#define NL '\n'
#define BS '\b'
#define RX_BUF_LEN 64
char rx_buf[RX_BUF_LEN+1] ; /* 1byte for NULL */
void print(char *str)
{
UART_UartPutString(str) ;
}
void printc(char c)
{
UART_UartPutChar(c) ;
}
int line_received = 0 ;
int rx_index = 0 ;
int get_line(void)
{
uint8_t c ;
while((line_received == 0) && (UART_SpiUartGetRxBufferSize() > 0)) {
c = UART_UartGetByte() ;
switch(c) {
case 0x00:
case 0xFF:
break ;
case BS: /* backspace */
if (rx_index > 1) {
rx_index-- ;
rx_buf[rx_index] = 0 ;
print("\b \b") ;
}
break ;
case NL:
case CR:
printc(c) ;
rx_buf[rx_index] = 0 ;
rx_index = 0 ;
line_received = 1 ;
break ;
default:
printc(c) ;
rx_buf[rx_index] = c ;
rx_index++ ;
if (rx_index >= RX_BUF_LEN) { /* buffer overflow */
rx_buf[RX_BUF_LEN] = 0 ; /* terminate the string */
line_received = -1 ; /* not 0 but not 1 as this is error */
rx_index = 0 ;
}
}
}
return(line_received) ;
}
void prompt(void)
{
print("> ") ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
print("\x1b[2J\x1b[;H") ; /* clear screen */
print("UART polling test ") ;
snprintf(rx_buf, RX_BUF_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(rx_buf) ;
prompt() ;
for(;;)
{
if (get_line()) {
print("Line: ") ;
print(rx_buf) ;
print("\n") ;
line_received = 0 ;
prompt() ;
}
}
}
=====================
(2) Interrupt version / 割込み使用版
schematic
pins
Tera Term log
main.c
==================
#include "project.h"
#include "stdio.h"
#define CR '\r'
#define NL '\n'
#define BS '\b'
#define RX_BUF_LEN 64
volatile char rx_buf[RX_BUF_LEN] ;
#define STR_LEN 32
char str[STR_LEN+1] ; /* 1 byte for NULL */
void print(char *str)
{
UART_UartPutString(str) ;
while(UART_SpiUartGetTxBufferSize() > 0) ;
}
void printc(char c)
{
UART_UartPutChar(c) ;
}
volatile int line_received = 0 ;
volatile int rx_write_index = 0 ;
int rx_read_index = 0 ;
int str_index = 0 ;
CY_ISR(uart_isr)
{
uint32_t status ;
uint8_t c ;
status = UART_GetRxInterruptSource() ;
if (status & UART_INTR_RX_NOT_EMPTY){
c = UART_UartGetByte() ;
if ((c != 0x00) && (c != 0xFF)) {
rx_buf[rx_write_index] = c ;
rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;
}
}
UART_ClearRxInterruptSource(status) ;
}
int get_line(void)
{
uint8_t c ;
while((line_received == 0)&&(rx_read_index != rx_write_index)) {
c = rx_buf[rx_read_index] ;
switch(c) {
case 0x00:
case 0xFF:
break ;
case BS: /* backspace */
if (str_index > 0) {
str_index-- ;
str[str_index] = 0 ;
print("\b \b") ;
}
break ;
case NL:
case CR:
printc(c) ;
str[str_index] = 0 ;
str_index = 0 ;
line_received = 1 ;
break ;
default:
printc(c) ;
str[str_index] = c ;
str_index++ ;
if (str_index >= STR_LEN) { /* buffer overflow */
str[STR_LEN] = 0 ; /* terminate the string */
line_received = -1 ; /* not 0 but not 1 as this is error */
str_index = 0 ;
}
}
rx_read_index = (rx_read_index + 1) % RX_BUF_LEN ;
}
return(line_received) ;
}
void prompt(void)
{
print("> ") ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
tty_rx_int_ClearPending() ;
tty_rx_int_StartEx(uart_isr) ;
UART_Start() ;
print("\x1b[2J\x1b[;H") ; /* clear screen */
print("UART interrupt test ") ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
prompt() ;
for(;;)
{
if (get_line()) {
print("Line: ") ;
print(str) ;
print("\n") ;
line_received = 0 ;
prompt() ;
}
}
}
==================
26-Jun-2020
moto
Show LessHi,
Today I noticed that my response to the question below was not kind enough,
especially for those new to PSoC.
So I wrote a couple of simpler samples for UART input char into array using CY8CKIT-059.
One is using polling and the other is using an interrupt.
I hope these are easier to understand comparing with the sample I suggested in the question.
(1) Polling mode (without using interrupt)
Note: This actually utilizes the component's internal interrupt, but from the view point of the programmer, it's a polling mode. (I hope)
schematic
UART config
pins
main.c
==============
#include "project.h"
#include "stdio.h"
#define CR '\r'
#define NL '\n'
#define BS '\b'
#define RX_BUF_LEN 64
char rx_buf[RX_BUF_LEN+1] ; /* 1byte for NULL */
void print(char *str)
{
UART_PutString(str) ;
}
void printc(char c)
{
UART_PutChar(c) ;
}
int line_received = 0 ;
int rx_index = 0 ;
int get_line(void)
{
uint8_t c ;
while((line_received == 0) && (UART_GetRxBufferSize() > 0)) {
c = UART_GetByte() ;
switch(c) {
case 0x00:
case 0xFF:
break ;
case BS: /* backspace */
if (rx_index > 1) {
rx_index-- ;
rx_buf[rx_index] = 0 ;
print("\b \b") ;
}
break ;
case NL:
case CR:
printc(c) ;
rx_buf[rx_index] = 0 ;
rx_index = 0 ;
line_received = 1 ;
break ;
default:
printc(c) ;
rx_buf[rx_index] = c ;
rx_index++ ;
if (rx_index >= RX_BUF_LEN) { /* buffer overflow */
rx_buf[RX_BUF_LEN] = 0 ; /* terminate the string */
line_received = -1 ; /* not 0 but not 1 as this is error */
rx_index = 0 ;
}
}
}
return(line_received) ;
}
void prompt(void)
{
print("> ") ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
UART_Start() ;
print("\x1b[2J\x1b[;H") ; /* clear screen */
print("UART polling test ") ;
snprintf(rx_buf, RX_BUF_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(rx_buf) ;
prompt() ;
for(;;)
{
if (get_line()) {
print("Line: ") ;
print(rx_buf) ;
print("\n") ;
line_received = 0 ;
prompt() ;
}
}
}
==============
Tera Term log
(2) Using an interrupt
schematic
UART config
pins
Note: pins are same with (1)
main.c
==================
#include "project.h"
#include "stdio.h"
#define CR '\r'
#define NL '\n'
#define BS '\b'
#define RX_BUF_LEN 64
volatile char rx_buf[RX_BUF_LEN] ;
#define STR_LEN 32
char str[STR_LEN+1] ; /* 1 byte for NULL */
void print(char *str)
{
UART_PutString(str) ;
while(UART_GetTxBufferSize() > 0) ;
}
void printc(char c)
{
UART_PutChar(c) ;
}
volatile int line_received = 0 ;
volatile int rx_write_index = 0 ;
int rx_read_index = 0 ;
int str_index = 0 ;
CY_ISR(uart_isr)
{
uint32_t status ;
uint8_t c ;
status = UART_ReadRxStatus() ;
if (status & UART_RX_STS_FIFO_NOTEMPTY){
c = UART_ReadRxData() ;
if ((c != 0x00) && (c != 0xFF)) {
rx_buf[rx_write_index] = c ;
rx_write_index = (rx_write_index + 1) % RX_BUF_LEN ;
}
}
}
int get_line(void)
{
uint8_t c ;
while((line_received == 0)&&(rx_read_index != rx_write_index)) {
c = rx_buf[rx_read_index] ;
switch(c) {
case 0x00:
case 0xFF:
break ;
case BS: /* backspace */
if (str_index > 0) {
str_index-- ;
str[str_index] = 0 ;
print("\b \b") ;
}
break ;
case NL:
case CR:
printc(c) ;
str[str_index] = 0 ;
str_index = 0 ;
line_received = 1 ;
break ;
default:
printc(c) ;
str[str_index] = c ;
str_index++ ;
if (str_index >= STR_LEN) { /* buffer overflow */
str[STR_LEN] = 0 ; /* terminate the string */
line_received = -1 ; /* not 0 but not 1 as this is error */
str_index = 0 ;
}
}
rx_read_index = (rx_read_index + 1) % RX_BUF_LEN ;
}
return(line_received) ;
}
void prompt(void)
{
print("> ") ;
}
int main(void)
{
CyGlobalIntEnable; /* Enable global interrupts. */
uart_rx_int_ClearPending() ;
uart_rx_int_StartEx(uart_isr) ;
UART_Start() ;
print("\x1b[2J\x1b[;H") ; /* clear screen */
print("UART interrupt test ") ;
snprintf(str, STR_LEN, "(%s %s)\n", __DATE__, __TIME__) ;
print(str) ;
prompt() ;
for(;;)
{
if (get_line()) {
print("Line: ") ;
print(str) ;
print("\n") ;
line_received = 0 ;
prompt() ;
}
}
}
==================
Tera Term log
moto
P.S. (edited) UART config screen shots were added.
Show Less
As some of you have already known, I have made this program for CY8CKIT-044, CY8CKIT-059, and CY8CKIT-062-BLE,
but as a yet another TSoC fan, I could not help doing this.
For those who don't know what TSoC is, it is a board with CY8C4146LQI-S433 and came with the "Transistor Gijutsu Magazine" in Japan.
ご存じの方もおいでのように、既にこのプログラムの CY8CKIT-044版、CY8CKIT-059版、CY8CKIT-062-BLE版を公開してきましたが、
やはりトラ技の TSoC 版を作らないわけにもいかないだろう(笑)と作ってみました。
ご存じではない方の為に、TSoC とは TQ出版 トランジスタ技術の 2019年5月号に付録としてついてきた
CY8C4146LQI-S433 搭載の PSoC 基板です。
Although I was expecting that the porting should be done with re-targeting the device and re-assigning pins,
but as CY8C4146LQI-S433 does not have UDB, I needed to use SCB version of SPI.
(And their APIs were slightly different, as usual 8-( )
デバイスを変えて、ピンのアサインだけし直せば、移植完了かなと期待していたのですが、
CY8C4146LQI-S433 には UDB が搭載されていないので、SPI には SCB タイプを使用する必要がありました。
(で、例によって API もちょっとずつ違うし・・・)
And the pin assignment(s)
But with this board the real work was after building the project.
Since the only user interface the board implemented was a LED on P0[3].
So I needed add
(1) A switch at P0[2]
(2) USB-Serial P1[0], P1[1] (KitProg provided them)
(3) I2C pull-up resistors and an I2C sensor (I used LM75B from the URL below)
(4) a POT to test ADC at P2[0]
(5) a LED to test PWM at P0[7]
(6) SPI, only pins were assigned
The result connection was like below
Note: The connection schematic was updated on 6-Jun-2022.
しかし、今回の仕事はむしろプロジェクトがビルドできてからでした。
TSoC が提供してくれているユーザーインターフェースが P0[3] の LED のみという思い切った構成の為
以下の外付け部品を用意しました。
(1) P0[2] にスイッチ
(2) P1[0], P1[1] に USB-Serial (KitProg の P12[7], P12[6]を使用)
(3) I2C 用に外付けのプルアップ抵抗と、I2C センサ (今回は下記 URL から LM75Bを使用しました)
(4) P2[0] に ADC 用の POT を接続
(5) P0[7] に PWM 実験用 LED を接続
(6) SPI にはピン設定だけで済ませてしまいました。
結果としては下記のような接続図になりました。
※回路図は 6-Jun-2022 に修正版になっています。
For a detailed command description, please refer to the CY8CKIT-044 version
コマンドの詳細は CY8CKIT-044 版をご覧ください。
MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-044 version)
So only a brief usage in this discussion.
このスレでは簡単な使用方法だけ説明します。
When the project is programmed and started, the top-level command menu will be displayed.
プログラムをダウンロードして起動すると、トップレベルのコマンドメニューが表示されます。
=== Memory ===
Entering "mem" at the prompt will change mode to "memory test" mode.
The prompt is now "mem> "
Command "dump 0x00" shows the memory contents of the first 256 bytes from 0x00.
Note: Although I wrote a command "write" use it at your own risk.
Entering "return" at the prompt return you to the top-level command.
プロンプトで “mem” と入力するとメモリーテストモードに入ります。
プロンプトが "mem> " に変わりました。
”dump 0x00" と入力すると 0x00 から 256 バイトのメモリの内容を表示します。
注意:とりあえず “write” コマンドも作ってはみましたが、使い方にはご注意ください。
プロンプトで "return" と入力するとトップレベルのコマンドに戻ります。
=== GPIO ===
Entering "gpio" at the top-level prompt let you enter "gpio test" mode.
Entering "write 0" will turn the on board LED OFF.
Entering "write 1" will turn the on board LED ON
Entering "read" will read the current value of GPIO pins.
"loop 20" sets the repeat number to 20
"interval 500" sets the interval between each loop 500ms
"run" will start the test loop.
Note: In this test I pushed and released the external switch a few times.
トップレベルのプロンプトに "gpio" と入力すると、“gpio test” モードに入ります。
“write 0” と入力すると、基板上の LED が消えます。
"write 1" と入力すると、基板上の LED が点灯します。
”read" と入力すると、GPIO の値を読みます。
"loop 20" と入力すると、繰り返し回数を 20回に設定します。
"interval 500" と入力すると、各ロープ間の待ち時間を 500ms に設定します。
"run" と入力すると、設定した loop 回、interval ms の間をあけて試行を行います。
下記の例では、実行中に外付けのスイッチ (IN) を何度か押したり、離したりしました。
=== ADC ===
The following is the screen shot of "adc test" mode.
"measure" triggers a single shot ADC reading.
"loop" and "interval" works just like "gpio test" mode.
In this example, I turned the POT from max to min and back.
下記は "adc test" モード実行時の画面コピーです。
"measure" を入力すると、一回だけ ADC 測定を行います。
”loop" と "interval" は前述の "gpio test" モードと同様に機能します。
下の例では、実行中に POT を最大から最小へ、そして少し戻すということをしました。
=== i2c ===
Entering "scan" command will let the I2C module scan the bus for the devices.
This command is handy when you have a device with unknown address.
Note: But some device requires to be addressed before they starts functioning,
for such device(s), this does not work.
In my test, LM75B had the adress 0x48.
So I set the slave address by entering "slave 0x48".
Then I can read/write from/to the device.
"scan" と入力すると、I2C バス上に存在するデバイスをスキャンします。
これはアドレスが分からない I2C デバイスのアドレスを知るときなどに便利です。
※直接そのアドレスにコマンドを送らないと、起きないデバイスもあり、
そういったデバイスの場合にはスキャンに引っかからない場合もあります。
今回のテストでは LM75B のアドレスは 0x48 でした。
"slave 0x48" と入力するとスレーブアドレスが 0x48 に設定されて
移行の read/write コマンドはそのスレーブを対象に行われます。
=== PWM ===
For the PWM test, we can set the "period" and "compare" or set both at once with "config"
Entering "period 1000" and "compare 500" makes the external LED toggles blinks a few time per sec.
Entering "config 10000 5000" makes the blinking 10 times slower.
Entering "config 100 90" makes the LED very bright.
Entering "config 100 30" dims it and "Config 100 0" will turn LED off.
PWM のテストでは周期を "period" で、デューティを "compare" で個々に設定するか
"config" でまとめて設定することが可能です。
”period 1000" と "compare 500" と入力すると外付けの LED が秒間数回点滅します。
"config 10000 5000" と入力すると点滅が 10倍遅くなります。
”config 100 90" と入力すると LED は明るく光ります。
"config 100 30" と入力すると LED は大分暗くなります。
"config 100 0" と入力すると LED は消灯します。
=== SPI ===
As I did not have appropriate SPI device, I just used MISO and MOSI for testing.
At first I enter "write 32" (Note this 32 is decimal)
Then SPI module sent out 32 and received a byte.
At this point, I was not connecting anything to the MISO, the value read was at the mercy of the board.
This time it returned 0.
Then I connected MISO to the VDD and entered "write 32",
it returned 0xFF (255) as the value read.
Next I connected MISO to the GND and no wonder the return value was 0
Finally, I connected MISO to the MOSI and I entered "write 32"
the read value was also "0x30 (32)".
To show that the SPI is working, I entered "write 33" and the returned value was also "0x21 (33)"
SPI のテスト用には適当なデバイスが見当たらなかったので、直接 MISO と MOSI を使用しました。
最初に MISO と MOSI を浮かせたままで "write 32" (この 32 は十進です)と入力しました。
この場合の読み込み値は基板や周囲の状況に依存するのですが、今回は 0 が返ってきていました。
次に、MISO を VDD に接続して、"write 32" と入力したところ
読み込み値は 0xFF (255) でした。
また、MISO を GND に接続して、"write 32" と入力したところ
読み込み値は 0x00 (0) でした。
最後に MISO と MOSI をジャンパで接続して "write 32" と入力したところ
読み込み値は 0x20 (32) でした。
念のために "write 33" と入力したところ
読み込み値は 0x21 (33) で、これも期待通りの値でした。
Now let me call it a day!
それでは今回はこの辺で!
moto
P.S. On 6-Jun-2022, it was found that in the top-level connection schematic,
SWD_CLK and SWD_DATA were connected to the wrong pins.
So connection diagram was updated.
This was a documentation level error and should not have effected the project
nor its behavior. But if a user connected TSoC and KitProg following the connection
diagram, the symptom would have been that in the Select Debug Target,
KitProg will be detected, but PSoC 4100S won't be.
The good news is that for this two years no complaint about this was posted in this discussion.
The bad news is ... I wonder if there is/are people using this project on this planet?
2022年6月6日、トップレベルの接続図上で SWD_CLK と SWD_DATA が
逆のピンに接続されていることがわかりましたので、修正しました。
これはドキュメントレベルの間違いでしたので、プロジェクトの内容や
実動作には影響がなかったと思われますが、接続図にしたがって TSoC と KitProg を
接続してしまった場合、KitProg は認識されるが、PSoC 4100S は認識されないという
状態になっていた恐れがあります。
良い知らせとしては過去2年間、この問題についての苦情がこのスレに投稿されることはありませんでした。
悪い知らせとしては、そもそもこのプロジェクト使った人がこの惑星上に存在していなかったかもという・・・
Show LessHaving been trying to help those new to PSoC, I've written many samples.
And I often repeated same mistakes by myself.
So I wondered if I make a sample which supports most of the common peripherals at once?
This motivated me to start building another tower of Babel...
初めて PSoC に触る方からのご質問にお答えするために、色々なサンプルを書いてきました。
しかし、同じペリフェラルで同じ失敗を繰り返すということも (今でも) 少なくありません。
それでは、とりあえず基本的なコンポーネントをまとめて面倒みちゃうサンプルを作っておいたら良いのでは?
という出来心でやってみました。
The basic concept of this sample is a Swiss Army Knife of MCU.
So far, I added basic test functions of "memory", "pwm", "adc", "i2c", "gpio", and "spi.
今回のテーマは MCU のスイスアーミーナイフ!
とりあえず、メモリー、PWM, ADC, I2C, GPIO, SPI の基本動作確認用の関数を入れてみました。
The schematics were separated for each functions/components so that removing/adding one will be easy.
追加/削除が容易に出来るようにと各機能毎に回路図を用意してみました。
schematics / 回路図
UART/TTY aka console / 俗にいうコンソール用
PWM
For easy monitoring, the output is connected to the LED Green.
動作が確認しやすいように出力は緑の LED に接続してあります。
ADC
I2C
SCL: P4[0]
SDA: P4[1]
GPIO
gpio_in is connected to SW2 (P0[7])
gpio_out is connected to LED Blue (P6[5])
SPI
SCLK P2[2]
MISO P3[0]
MOSI P3[1]
CS0 P2[3]
Pin list
When program starts, the top level menu and prompt will be shown.
プログラムを起動するとトップレベルのメニューとプロンプトが表示されます。
=== Memory / メモリー ===
Entering "mem" at the top-level prompt brings you to "Memory" test mode.
トップレベルのプロンプトで “mem” と入力すると“Memory” のテストモードに入ります。
Note that the prompt is now "mem> ".
プロンプトが “mem> ” に変わりました。
Entering "read 0x00" will show you the value in the address 0x00000000.
And Entering "dump 0x20000000" will show you a 256 bytes dump from the beginning of the SRAM.
Although I added "write" command, proceed at your own risk.
“read 0x00” と入力するとアドレス 0x00000000 の値が表示されます。
“dump 0x20000000” と入力すると SRAM の先頭アドレス 0x20000000 から 256 バイトのダンプが表示されます。
“write” コマンドも作ってはありますが、色々危なそうなので自己責任でお試しください。
Entering "return" at the "mem> " prompt bring you back to the top-level.
“mem> ” プロンプトに “return” と入力するとトップレベルに戻ります。
=== PWM ===
Entering "pwm" at the top-level prompt brings you to the "PWM" test mode.
トップレベルのプロンプトで “pwm” と入力すると “PWM” テストモードに入ります。
Entering "status" shows you the current setup.
period = 1000, compare = 0, which means the output is always 0 and LED Green is always ON.
“status” と入力すると現在の設定が表示されます。
周期 = 1000, コンペア = 0 なので、出力は常に 0 になっていて、緑の LED は点灯しつづけています。
Entering "config 1000 500" will make LED Green blinks 10 times a second.
“config 1000 500” と入力すると、緑の LED が一秒間に10回点滅を始めます。
Entering "stop" stops the PWM and LED turns off.
“stop” と入力すると PWM が停止して、LED は消灯します。
Entering "config 10000 5000" will make the period 1 sec. 50% duty.
“config 10000 5000” と入力すると周期は 1秒、デューティは 50% になります。
Entering "start" again, will let LED Green blink each seconds.
“start” と入力すると緑の LED は毎秒点灯します。
To go to the next section enter "stop" and "return."
次の説明に進むのには、“stop” と “return” を入力しておいてください。
=== ADC ===
To test ADC, I added an external pot at 3.3V, AN0 (P2[0]), GND.
If you don't have a POT, may be using jumper wire to connect P2[0] to 3.3V or GND will show you how it's like.
ADC をテストするために外付けの POT を 3.3V, AN0 (P2[0]), GND に接続しました。
もし POT をお持ちでない場合には、ジャンパワイヤで P2[0] を 3.3V や GND に当ててやると雰囲気は分かると思います。
Enter "adc" at the top-level menu will bring you to "ADC" Test mode.
トップレベルメニューから “adc”と入力すると “ADC” テストモードに入ります。
"status" command shows you current setup of the ADC test mode.
“status” コマンドの入力すると ADC テストモードの現在の設定が表示されます。
As the picture above, entering "loop 20", "interval 500", "status" commands makes the setup as
repeat measurement 20 times with the interval of 500 ms.
上の絵のように、“loop 20”, "interval 500", "status" とコマンドを入力すると
500 ms 毎に 20 回測定を繰り返すという設定になります。
BTW, entering just "measure" will trigger measure once.
Here we could see the value 1.642 V, so the POT was about in the middle position.
Entering "run" triggers the 20 times measurements.
I moved the POT during the run, as you can see above.
ところで、単に “measure” と入力すると単発の測定が行われます。
ここでは 1.642 V と表示されていたので、POT は大体真ん中辺りにあったことが分かります。
“run” と入力すると 20 回の連続測定が開始されます。
この間に POT のつまみを動かしたのが上記の画面になります。
As usual to proceed, enter "return"
例によってトップレベルに戻るのには “return” と入力しておいてください。
=== I2C ===
Enter "i2c" at the top-level menu will bring you to "I2C" Test mode.
トップレベルメニューから “i2c”と入力すると “I2C” テストモードに入ります。
To begin with, I enter "scan" command, which will scan the bus and list up the devices present.
This is handy, when you don't know the I2C address of a particular device/module.
とりあえず、“scan” というコマンドを入力すると、バス上にあるデバイスをリストアップしてくれます。
これはアドレス不明の I2C デバイス/モジュールのアドレスを特定するのにも便利です。
Now thanks for the kit guide, we know that the device at 0x0F is Kionix KXTJ2.
キットガイドのおかげで、0x0F にあるのは Kionix KXTJ2 だとわかりました。
http://kionixfs.kionix.com/en/datasheet/KXTJ2-1009%20Specifications%20Rev%209.pdf
According to the datasheet, register address 0x0F is "WHO_AM_I" and supposed to return "0x09"
データシートによるとレジスタアドレス 0x0F は “WHO_AM_I” で “0x09” を読み出せるはずです。
First enter "slave 0x0F" to set the slave address to 0x0F.
Then "readreg 0x0F" will read the register 0x0F from the specified slave address.
And fortunately we got 0x09 (9)
先ず、“slave 0x0F” と入力して、スレーブアドレスを 0x0F に設定します。
次に "readreg 0x0F" というコマンドを入力することで指定したスレーブのレジスタアドレス0x0F の値を読み出します。
幸いにして、0x09 (9) と読み出すことが出来ました。
Also from the datasheet, 6 bytes from 0x06 are X, Y, Z output and 0x0C returns 0x55.
また、データシートでは 0x06 から 6 bytes が、X, Y, Z の出力、 0x0C が 0x55 を返すようです。
So I entered "readregs 0x06 7" and got the values below.
というわけで、“readregs 0x06 7” と入力したところ下記の値を取得しました。
As usual to proceed, enter "return"
例によってトップレベルに戻るのには “return” と入力しておいてください。
=== GPIO ===
Enter "gpio" at the top-level menu will bring you to "GPIO" Test mode.
トップレベルメニューから “gpio”と入力すると “GPIO” テストモードに入ります。
Entering "status" shows us current status of GPIO, both input and output are 1 now.
With this sample GPIO input is SW2 and GPIO output is LED Blue.
“status” と入力すると GPIO の現在の状態が表示されます。
このサンプルでは入力は SW2, 出力は 青色 LED に設定されています。
Entering "write 0" turns the Blue LED ON and "write 1" turns it OFF.
Entering "read" command shows us the value of both input and output.
“write 0” と入力すると青い LED が点灯します、“write 1” と入力すると青い LED が消灯します。
“read” と入力すると、入力、出力の現在値が表示されます。
Entering "loop 20", "interval 500", "run" will start 20 time repeat of GPIO test.
During this, I pushed and released SW2 which was reflected to the value of IN,
on the other hand output was automatically toggled.
“loop 20”, "interval 500", "run" と入力すると 20 回のテストループに入ります。
私が SW2 を押したり離したりしたので IN の値が変化しています、
一方、OUT の値は無条件で毎回トグルするようになっています。
As usual to proceed, enter "return"
例によってトップレベルに戻るのには “return” と入力しておいてください。
=== SPI ===
Enter "spi" at the top-level menu will bring you to "SPI" Test mode.
トップレベルメニューから “spi”と入力すると “SPI” テストモードに入ります。
Entering "status" shows us the current setup.
Now without using jumper wire or connecting to other spi device,
entering "write 32" will show
TX: 0x20 (32)
RX: 0xFF (255)
“status” と入力すると現在の設定が表示されます。
ジャンパワイヤや外部の SPI デバイスを接続しない状態で
“write 32” と入力すると
TX: 0x20 (32)
RX: 0xFF (255)
と表示されました。
Next I shorted MISO P3[0] and MOSI P3[1] with a jumper wire.
And entering "write 32" gave us.
TX: 0x20 (32)
RX: 0x20 (32)
次に MISO P3[0] と MOSI P3[1] をジャンパワイヤでショートして
“write 32” と入力したところ
TX: 0x20 (32)
RX: 0x20 (32)
となりました。
Finally, entering "loop 20", “internal 500”, "run 32" resulted the screen below.
最後に“loop 20”, “interval 500”, "run 32" と入力したところ下記の画面のようになりました。
=====================
3-May-2020
Motoo Tanaka
P.S. From the version 200504, Backspace is supported.
So please us the newer version in the response message,
unless you are a person who never mistypes.
追伸: 200504 版からバックスペースに対応しました。
絶対にタイプミスをしない!という超人の方以外は
レスポンスに添付してある新しいヴァージョンをの方をご使用ください。
5-May-2020
Some spelling corrections.
ミススペル等、少々修正しました。
Show LessHi,
I've been trying to include same project in different workspaces on PSoC Creator 4.3, with the reason being to debug multiple devices simultaneously.
I'd like to ask is it possible to do so? And, by saying that, I mean including the same project in different workspaces without any conflicts in building/debugging the two separate project "instances". If so, then how?
Thanks!
Show Less