Code Examples Forum Discussions
text.format{('custom.tabs.no.results')}
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 LessHi all,
I am making some programs for beginners using Modus ToolBox 2.1. When migrating the development environment from PSoc Creator to Modus, I had a hard time creating a simple program. Especially, there are few simple samples using the Device Configuration tool.
Here, a simple program for the M4 core of PSoC 6 using the Device Configuration tool of Modus Toolbox2.1 is introduced here.
The environment is as follows.
This time, use the Timer interrupt to set the LED lighting time.
Select the CY8CKIT-062-BLE kit from the New Application tool in the Quick Panel and use it based on what was created in the empty PSoC 6 app.
About the pin setting, start the Device Configuration tool from the Quick Panel in the IDE of Modus Toolbox2.1, and set it according to the following procedure.
Select the “Pin” tab.
Check P0[3], name it "LED" and select "Drive Mode" as "Strong Drive, Input buffer off".
Move to “peripheral” tab
Check "TCPWM [1] 16bit Timer Counter 0", select Timer-Counter-1.0, and name it "Timer".
The parameter settings are as follows.
Period:10000
Interrupt Source:Overflow & Underflow
Clock Signal:16bit Divider 0 clk
Go to the “Peripheral-Clocks” tab.
Check the 16bit Divider 0 specified in the PWM. Divide by 10,000.
Divider: 10000
Since the clock source is 100MHz, 10KHz divided by 10,000 is output.
Make sure that "TCPWM [1] 16bit Counter (Timer)" is selected as the connection destination of Peripheral.
The program is as follows.
#include "cy_pdl.h"
#include "cyhal.h"
#include "cybsp.h"
#define SWITCH_INTR_PRIORITY (3u)
const cy_stc_sysint_t switch_intr_config = {
.intrSrc = Timer_IRQ, /* Source of interrupt signal */
.intrPriority = SWITCH_INTR_PRIORITY /* Interrupt priority */
};
void Timer_isr(void){
Cy_GPIO_Inv(LED_PORT, LED_NUM);
Cy_TCPWM_ClearInterrupt(Timer_HW, Timer_NUM, CY_TCPWM_INT_ON_TC);
}
int main(void)
{
cy_rslt_t result;
/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
Cy_TCPWM_Counter_Init(Timer_HW, Timer_NUM, &Timer_config);
Cy_TCPWM_Counter_Enable(Timer_HW, Timer_NUM);
Cy_SysInt_Init(&switch_intr_config, Timer_isr);
NVIC_ClearPendingIRQ(switch_intr_config.intrSrc);
NVIC_EnableIRQ(switch_intr_config.intrSrc);
__enable_irq();
Cy_TCPWM_TriggerStart(Timer_HW, Timer_MASK);
for (;;)
{
}
}
It's easy. First, why don't you get used to Modus toolbox from this program?
Thanks,
Show LessHi all,
I am making some programs for beginners using Modus ToolBox 2.1. When migrating the development environment from PSoc Creator to Modus, I had a hard time creating a simple program.
Here, a simple program for the M4 core of PSoC 6 using Modus Toolbox2.1 is introduced here.
The environment is as follows.
Last time, I used UART by setting SCB with the Device Configuration tool, but there is a library that can use the printf() function more easily. It's also used in the "Hello World" example, but here's an extract of only the UART output settings using printf () with Retarget IO Library.
Select the CY8CKIT-062-BLE kit from the New Application tool in the Quick Panel and use it based on what was created in the empty PSoC 6 app.
The Device Configuration tool in the IDE of Modus Toolbox2.1 is not used for Pin and UART related component settings.
Launch the Library Manager from the Quick Panel to add the Retarget IO Lib to your project as follows.
Go to the “Libraries” tab in the Library Manager and check retarget-io.
After checking, click the “Apply” button at the bottom right to close the Library Manager.
Then all you have to do is write the program.
The program is as follows.
#include "cy_pdl.h"
#include "cyhal.h"
#include "cybsp.h"
#include "cy_retarget_io.h"
int main(void)
{
cy_rslt_t result;
/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
result = cy_retarget_io_init(CYBSP_DEBUG_UART_TX, CYBSP_DEBUG_UART_RX, CY_RETARGET_IO_BAUDRATE);
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
__enable_irq();
/* \x1b[2J\x1b[;H - ANSI ESC sequence for clear screen */
printf("\x1b[2J\x1b[;H");
printf("PSoC 6 MCU: Hello World! Example \r\n\n");
for (;;)
{
}
}
Since I used TeraTerm as a terminal, the setting is described below.
Note: “Port” is depending on the PC environment.
It's very easy. Please use it for debugging in the Modus Toolbox environment.
Thanks,
Show LessHi all,
I am making some programs for beginners using Modus ToolBox 2.1. When migrating the development environment from PSoc Creator to Modus, I had a hard time creating a simple program. Especially, there are few simple samples using the Device Configuration tool.
Here, a simple program for the M4 core of PSoC 6 using the Device Configuration tool of Modus Toolbox2.1 is introduced here.
The environment is as follows.
This time, it is a method to output a message on the terminal by using the UART function of SCB.
Select the CY8CKIT-062-BLE kit from the New Application tool in the Quick Panel and use it based on what was created in the empty PSoC 6 app.
About the pin setting, start the Device Configuration tool from the Quick Panel in the IDE of Modus Toolbox2.1, and set it according to the following procedure.
Go to “Peripheral” tab.
Check Serial Communication Block (SCB) 5, Name is "KIT_UART".
Personality chooses “UART = 1.0”.
Also set the parameters on the right. For communication settings, use the above settings (default) and set the following.
Clock:8bit Divider 1 clk
Rx:P5[0] digital_inout
Tx:P5[1] digital_inout
Now you can set Pin and Clock at the same time. Just in case, check the “Pin” and “Peropheral-Clocks” tabs.
The program is as follows. The message is output by the Cy_SCB_UART_PutString() function.
int main(void)
{
cy_rslt_t result;
cy_stc_scb_uart_context_t KIT_UART_context;
/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
/* Turn on the UART */
Cy_SCB_UART_Init( KIT_UART_HW, &KIT_UART_config, &KIT_UART_context );
Cy_SCB_UART_Enable( KIT_UART_HW );
__enable_irq();
Cy_SCB_UART_PutString(KIT_UART_HW, "Hello PSoC \n\r" );
for (;;)
{
}
}
Since I used TeraTerm as a terminal, the setting is described below.
Note: “Port” is depending on the PC environment.
It's easy. First, why don't you get used to Modus toolbox from this program?
Thanks,
Show LessHi all,
I am making some programs for beginners using Modus ToolBox 2.1. When migrating the development environment from PSoc Creator to Modus, I had a hard time creating a simple program. Especially, there are few simple samples using the Device Configuration tool.
Here, a simple program for the M4 core of PSoC 6 using the Device Configuration tool of Modus Toolbox2.1 is introduced here.
The environment is as follows.
This time, we will use PWM to change the LED brightness using the compare. This is an example of changing the brightness by using compare as the base of "PWM that changes the brightness of LED".
Select the CY8CKIT-062-BLE kit from the New Application tool in the Quick Panel and use it based on what was created in the empty PSoC 6 app.
About the pin setting, start the Device Configuration tool from the Quick Panel in the IDE of Modus Toolbox2.1, and set it according to the following procedure.
Select the “Pin” tab.
Check P0[3], name it "LED" and select "Drive Mode" as "Strong Drive, Input buffer off".
The peripherals that can be connected to P0[3] is displayed in the pull-down menu in Digital Output in Parameters on the right. Select "TCPWM[0] 32bit Counter 1 pwm_n" from the pull-down menu.
Go to “Peripheral” tab and set TCPWM (Timer Counter PWM) as PWM.
Check TCPWM [0] 32bit Counter 1 selected as Digital output of Pin0 [3]. Then, a selection window will appear. Select "PWM-1.0". Enter Name as "PWM".
On the right side of the Peripheral tab, there is a place to set the PWM parameters. Set the comparison Compare that determines the period and the pulse width.
Period:1000
Compare:100
Select the input clock source from the pull-down menu.
Clock Signal:16bit Divider 0 clk
make sure that what is set as Pin output is selected as PWM output.
PWM_n:P0[3]
Go to the Peripheral-Clocks tab.
Check "16bit Divider 0" specified in PWM.
The division is 8.
Divider: 8
Since the clock source is 100MHz, 12.5MHz divided by 8 is output.
Make sure that "TCPWM [0] 32bit Counter (PWM)" is selected as the Peripheral connection destination.
The program is as follows.
int main(void)
{
cy_rslt_t result;
int compare = 0 ;
/* Initialize the device and board peripherals */
result = cybsp_init() ;
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
Cy_TCPWM_PWM_Init(PWM_HW, PWM_NUM, &PWM_config);
Cy_TCPWM_PWM_Enable(PWM_HW, PWM_NUM);
__enable_irq();
Cy_TCPWM_TriggerStart(PWM_HW, PWM_MASK);
for (;;)
{
Cy_TCPWM_PWM_SetCompare0 (PWM_HW, PWM_NUM, compare++);
if (compare >= 1000) {
compare = 0 ;
}
CyDelay(1) ;
}
}
It's very easy. Why don't you get used to Modus toolbox with this program?
Thanks,
Show Less