Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
spi_slave.cpp
00001 #include "mbed.h" 00002 00003 SPISlave to_cdh(p5,p6,p7,p8); // mosi, miso, sclk, ssel 00004 Serial pc(USBTX,USBRX); 00005 /*DigitalOut myleds[4] = {LED1,LED2,LED3,LED4}; // mbed動作目視確認用LED 00006 DigitalOut ADC_on(p21); // ADC用のスイッチをONにするピン 00007 DigitalOut ADC_off(p22); // ADC用のスイッチをOFFにするピン 00008 DigitalOut COM_on(p23); 00009 DigitalOut COM_off(p24); 00010 DigitalOut myled(LED1); 00011 00012 AnalogIn v(p16); 00013 SPI spi(p11,p12,p13); 00014 MCP3208 mcp3208(spi,p14); 00015 DigitalOut dyn(p25);*/ 00016 00017 /*float v_bat[5], EPS_cur[5], ADC_cur[5], dyn_cur[5]; 00018 int data;*/ 00019 00020 int main() 00021 { 00022 pc.printf("--Hi,this is eps(slave).\r\n"); 00023 to_cdh.format(8,3); 00024 to_cdh.frequency(1000000); 00025 00026 int sdummy = 0x0F; 00027 to_cdh.reply(sdummy); // set dummy data (通信前に事前にセット) 00028 00029 while(1) { 00030 if(to_cdh.receive()) { 00031 int rcmd = to_cdh.read(); 00032 00033 if(rcmd == 0x01){ 00034 int sdata = 0x99; 00035 to_cdh.reply(sdata); 00036 pc.printf("rcmd: %02x, ",rcmd); 00037 pc.printf("send data: %02x\r\n",sdata); 00038 } 00039 00040 // 2byte data 00041 else if(rcmd == 0x02){ 00042 int sdata1 = 0x21; 00043 int sdata2 = 0x22; 00044 to_cdh.reply(sdata1); 00045 to_cdh.reply(sdata2); 00046 pc.printf("rcmd: %02x, ",rcmd); 00047 pc.printf("send data: %02x, %02x\r\n",sdata1,sdata2); 00048 } 00049 else if(rcmd == 0xFF){ 00050 to_cdh.reply(sdummy); 00051 } 00052 } 00053 } 00054 }
Generated on Fri Jul 29 2022 01:28:45 by
1.7.2