MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-044 version)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Having 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 に触る方からのご質問にお答えするために、色々なサンプルを書いてきました。

しかし、同じペリフェラルで同じ失敗を繰り返すということも (今でも) 少なくありません。

それでは、とりあえず基本的なコンポーネントをまとめて面倒みちゃうサンプルを作っておいたら良いのでは?

という出来心でやってみました。

IMG_4256.JPG

 

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 / 俗にいうコンソール用

000-tty.JPG

PWM

 

For easy monitoring, the output is connected to the LED Green.

 

動作が確認しやすいように出力は緑の LED に接続してあります。

001-pwm.JPG

ADC

002-adc.JPG

I2C

SCL: P4[0]

SDA: P4[1]

003-i2c.JPG

GPIO

gpio_in is connected to SW2 (P0[7])

gpio_out is connected to LED Blue (P6[5])

004-gpio.JPG

SPI

SCLK P2[2]

MISO P3[0]

MOSI P3[1]

CS0   P2[3]

005-spi.JPG

Pin list

006-pin-list.JPG

 

When program starts, the top level menu and prompt will be shown.

プログラムを起動するとトップレベルのメニューとプロンプトが表示されます。

010-top-menu.JPG

 

=== Memory / メモリー ===

 

Entering "mem" at the top-level prompt brings you to "Memory" test mode.

トップレベルのプロンプトで “mem” と入力すると“Memory” のテストモードに入ります。

011-top-mem.JPG

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” コマンドも作ってはありますが、色々危なそうなので自己責任でお試しください。

020-memory-1.JPG

 

Entering "return" at the "mem> " prompt bring you back to the top-level.

“mem> ” プロンプトに “return” と入力するとトップレベルに戻ります。

021-return-from-mem.JPG

 

=== PWM ===

Entering "pwm" at the top-level prompt brings you to the "PWM" test mode.

トップレベルのプロンプトで “pwm” と入力すると “PWM” テストモードに入ります。

031-PWM.JPG

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 に当ててやると雰囲気は分かると思います。

040-ADC.JPG

 

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 回測定を繰り返すという設定になります。

 

041-ADC2.JPG

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” テストモードに入ります。

050-i2c.JPG

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) と読み出すことが出来ました。

051-i2c-2.JPG

 

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 を返すようです。

053-register-map.JPG

 

So I entered "readregs 0x06 7" and got the values below.

というわけで、“readregs 0x06 7” と入力したところ下記の値を取得しました。

052-i2c-3.JPG

As usual to proceed, enter "return"

例によってトップレベルに戻るのには “return” と入力しておいてください。

 

=== GPIO ===

 

Enter "gpio" at the top-level menu will bring you to "GPIO" Test mode.

トップレベルメニューから “gpio”と入力すると “GPIO” テストモードに入ります。

060-gpio-1.JPG

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 に設定されています。

 

062-gpio-3.JPG

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 の値は無条件で毎回トグルするようになっています。

061-gpio-2.JPG

 

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)

と表示されました。

070-spi-1.JPG

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)

となりました。

071-spi-2.JPG

 

Finally, entering "loop 20", “internal 500”, "run 32" resulted the screen below.

最後に“loop 20”, “interval 500”, "run 32" と入力したところ下記の画面のようになりました。

 

072-spi-3.JPG

=====================

 

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.

ミススペル等、少々修正しました。

5 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

As the required command string gets longer or more complicated,

I noticed that not handling "Backspace" is annoying.

I really felt the frustration while I was debugging this project,

so I confessed and finally modified my tty_utils to handle "Backspace".

プログラムの要求する入力が複雑かつ長くなるにつれて、

バックスペースが効かないことにイライラし始めました。

とくにこのプロジェクトのデバッグ時はキツかったので、

ついに懺悔して、tty_utils をバックスペース対応に修正することにしました。

tty_utils a utility sample for CLI type program

Then this MCU Tester project also now supports "Backspace".

Although most of my sample programs required the serial terminal with local echo,

from this version on local echo is not required.

And "Backspace" should work (I hope).

結果、この MCU Tester プロジェクトもバックスペースに対応しました。

これまで、私のサンプルの殆どはシリアルターミナルをローカルエコー有効で

使用する設定にしていたのですが、このヴァージョン以降はローカルエコーは不要となりました。

そして、バックスペースも使えます。(と思う)

moto

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Since then I added PSoC 5LP version and PSoC 6 version of this program.

その後、このプログラムの PSoC 5LP 版と PSoC 6 版を作成しました。

MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-059 version)

MCU Tester, a Swiss Army Knife for PSoC (CY8CKIT-062-BLE version)

During the time writing them, I added some features to i2c.

Which were loop, interval and delay.

delay is for the delay between writing address and reading the data.

loop and interval is just like other function,

let some function repeat loop times

with interval of "interval" ms.

それらを書いている内に i2c に少し機能を追加しました、

loop, interval, delay です。

delay はアドレスを書き込んでからデータを読むまでの遅延です。

loop と interval は他の機能と同様に、いくつかのコマンドを

loop 回、interval ms の間隔で実行するようにしました。

What is good about it?

それ何が嬉しいの?

For example, let's try with the on board KXTJ2.

After selecting the slave with "slave 0x0F" command.

If I read register 0x0F (WHO_AM_I) with "readreg 0x0F" we get 0x09.

But if I read registers from 0x06 to 0x0C, I can not see the dynamics.

At first, when I read regs with "loop 5", "interval 100", "readregs 6 7",

all the X, Y, Z are constants. As the mode of sensor is not activated.

Then I write 0x80 to the CTRL_REG1 (0x1B) to activate the sensor.

Trying "loop 10", "interval 100", "readregs 6 7", showed us the movement of the board.

(I was moving the board with my hand)

例えば、基板に乗っている KXTJ2 で実験してみましょう。

先ず、"slave 0x0F" コマンドで当該センサを選びます。

"readreg 0x0F" で WHO_AM_I レジスタを読むとちゃんと 0x09 が返ってきます。

しかし X, Y, Z の値がある 0x06 から 0x0C を普通に読んだだけでは動きがわかりません。

そこで "loop 5", "interval 100", "readreg 6 7" を試してみると、値に変化はありません。

センサがスタンバイモードにいるからですね。

そこで、CTRL_REG1 (0x1B) に 0x80 を書き込んでセンサを動作モードに変えます。

次に "loop 10", "interval 100", "readregs 6 7" とやるとセンサの値が動的に動いているのがわかります。

(その時、基板を持って手で動かしていました。)

102-i2c-3.JPG

28-May-2020

moto

0 Likes
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

I added schematic page enable/disable support.

Except tty, each schematic page can be enabled/disabled before compiling the project.

tty 以外の回路図ページを個別にenable / disable 出来るようになりました。

テストしたいコンポーネント以外のページを disable することで、必要なコンポーネントだけのテストが可能になりました。

Please refer to the description in the following sample.

使用方法は下記のサンプルページをご参照ください。

PSoC Creator Schematic Page Enable/Disable Sample

moto

0 Likes
LiDo_2439176
Level 5
Level 5
First question asked 50 replies posted 50 sign-ins

Awesome, thank you for sharing your knowledge with us.

Liviu

Takashi_M
Moderator
Moderator
Moderator
1000 replies posted 500 solutions authored 750 replies posted

Dear Moto-san,

We appreciate your contribution for this.

Best regards.