こんにちは。NoMaYです。TB-RX65N/RX130/RX231のCS+のサンプルプログラムです。まずはデバッグコンソール出力のサンプルです。(サンプルプログラム置き場とGitHubに置きました。)japan.renesasrulz.com/cafe_rene/m/sample_program/460github.com/NoMaY-jp/RX_SmartConfigurator_examples_RXTB_CSplus/tree/cafe_rene/10_DebugConsole_printf
int main(void){ LED0 = LED_ON; for (;;) { printf( "Hello World\r\n" ); R_BSP_SoftwareDelay( 1000, BSP_DELAY_MILLISECS ); LED0 = ~LED0; R_BSP_SoftwareDelay( 1000, BSP_DELAY_MILLISECS ); LED0 = ~LED0; }}
こんにちは。NoMaYです。TB-RX65N/RX130/RX231のCS+のサンプルプログラムです。I2C送受信のサンプルを追加しました。(サンプルプログラム置き場とGitHubに置きました。) なお、今回、手っ取り早く通信相手を用意したかったので、RX72N Envision Kit及びそれに搭載されているライトセンサISL29034を使用したことにより、TBボードに関してはビルド出来ることまでしか確認していないです。japan.renesasrulz.com/cafe_rene/m/sample_program/460github.com/NoMaY-jp/RX_SmartConfigurator_examples_RXTB_CSplus/tree/cafe_rene/60_I2C_Master
U_CONFIG_I2C_MASTER_IMPL( SCI11 );int main(void){ /* ISL29034 data sheet: https://www.renesas.com/jp/ja/doc/datasheet/isl29034.pdf */ uint8_t adr7_ISL29034 = 0x44; /* The 7-bits address of the device */ uint8_t cmd_read_ID[1] = { 0x0F /* Address of the ID register */ }; uint8_t cmd_clr_BOUT[2] = { 0x0F, /* Address of the ID register */ 0x00 /* Write data (the BOUT bit is the bit7 of the ID register) */ }; uint8_t ret_data1[1] = { 0x00 }; /* Just clear before reception */ uint8_t ret_data2[1] = { 0x00 }; /* Just clear before reception */ printf( "Hit 'Enter' key to proceed the operation.\r\n" ); getchar(); U_Config_I2C_Master_Start( SCI11 ); U_Config_I2C_Master_Send_UWT( SCI11, adr7_ISL29034, cmd_read_ID, sizeof(cmd_read_ID) ); U_Config_I2C_Master_Receive_UWT( SCI11, adr7_ISL29034, ret_data1, sizeof(ret_data1) ); printf( "Read the initial value of the ID register: " ); printf( "(val & 0xA8) = 0x%02x (expected: 0xA8)\r\n\r\n", ret_data1[0] & 0xA8 );11/26変更 printf( "(val & 0xA8) = 0x%02X (expected: 0xA8)\r\n\r\n", ret_data1[0] & 0xA8 ); U_Config_I2C_Master_Send_UWT( SCI11, adr7_ISL29034, cmd_clr_BOUT, sizeof(cmd_clr_BOUT) ); printf( "Clear the BOUT bit (the bit7 of the ID register).\r\n\r\n" ); U_Config_I2C_Master_Send_UWT( SCI11, adr7_ISL29034, cmd_read_ID, sizeof(cmd_read_ID) ); U_Config_I2C_Master_Receive_UWT( SCI11, adr7_ISL29034, ret_data2, sizeof(ret_data2) ); printf( "Read again the value of the ID register: " ); printf( "(val & 0xA8) = 0x%02x (expected: 0x28)\r\n\r\n", ret_data2[0] & 0xA8 );11/26変更 printf( "(val & 0xA8) = 0x%02X (expected: 0x28)\r\n\r\n", ret_data2[0] & 0xA8 ); printf( "Done.\r\n" ); for (;;) { }}
なお、Config_ext.hというヘッダをプロジェクトに追加して、r_cg_macrodriver.hの中からインクルードして下さい。(このヘッダにはパズルのようなマクロを記述してありますが、ちょっと初学者向きでは無いですので、説明は省略します。すみません。) また、Config_ext.hは、どのSCIチャンネルでも使用出来るようになっていますが、サンプルプログラムで使用しているSCIチャンネル以外を使用する場合は、予め、使用するSCIコンポーネントをRXスマートコンフィグレータで生成しておいて下さい。プロジェクトツリー: File/Smart Configurator/general/r_cg_macrodriver.h変更内容: 赤文字箇所を追加
/******************************************************************************Global functions******************************************************************************/void R_Systeminit(void);/* Start user code for function. Do not edit comment generated here */#include "Config_ext.h"/* End user code. Do not edit comment generated here */
実行例: (今回はRX72N Envision Kitを使用しました。)[関連スレッド]RX231のコード生成を用いた簡易IIC通信についてjapan.renesasrulz.com/cafe_rene/f/002-2095199602/6169/rx231-iic/34171#34171japan.renesasrulz.com/cafe_rene/f/002-2095199602/6169/rx231-iic/34173#34173「今回、送信完了/受信完了を待つ送信関数名/受信関数名の末尾に _UWT を付けてみました。(unlimited wait timeの意。また、先頭を R_ ではなくて U_ にしてあります。ちなみに、STM32CubeMXでは送信完了/受信完了を待たない関数の名前の末尾に _IT を付けるようでしたので、逆向きに(?)真似てみました。)」「以下は私のチョンボですね。」