Chihiro H
/
Microchip23K256_demo
Microchip 23K256 (SPI SRAM) sample code for https://www.switch-science.com/catalog/1072/ module.
Diff: main.cpp
- Revision:
- 2:0248049e65f1
- Parent:
- 1:793321f410a9
- Child:
- 3:65a33de8fa08
--- a/main.cpp Fri Oct 31 13:07:40 2014 +0000 +++ b/main.cpp Sat Nov 01 13:58:50 2014 +0000 @@ -1,14 +1,47 @@ +/* + * test for + * - Microchip SRAM 23K256 (SPI) + * - Intersil Red/Green/Blue Color Light Sensor (I2C, address = 1000 100x, hard-wires) + * - ISL29125 data sheet, p.7, Device Adressing + * - + */ + #include "mbed.h" +/** Serial port for DEBUG */ +Serial pc(USBTX, USBRX); + +InterruptIn mybutton(USER_BUTTON); + +/** ユーザーボタンが押されたらtrue */ +volatile bool is_pressed = false; + +/** + * USERボタン 割り込みハンドラ + */ +void +pressed() { + is_pressed = true; +} + +/** + * USERボタンが押されるまで待つ。 + */ +void +wait_until_user_button_pressed() { + while (!is_pressed) { + __nop(); + } + is_pressed = false; + pc.printf("USER button is pressed\r\n"); +} + /** */ SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); /** */ DigitalOut cs(SPI_CS); -/** for DEBUG */ -Serial pc(USBTX, USBRX); - /* * SPI COMMAND (Microchip 23K256 SRAM) * 1byte read/write @@ -283,12 +316,17 @@ pc.printf("read: 0x%02x\r\n", value); } + /** * 動作確認用。TODO: テストコードにすること。 */ int main() { + mybutton.fall(&pressed); + + wait_until_user_button_pressed(); + // initialize spi.format(8, 0); // 8bit, mode=0 spi.frequency(20 * 1000 * 1000); // max 20MHz @@ -296,10 +334,18 @@ // test pc.printf("TEST START\r\n"); + + wait_until_user_button_pressed(); try_single_byte_access(); + + wait_until_user_button_pressed(); try_byte_access(); + try_page_access(); + + wait_until_user_button_pressed(); try_sequential_access(); + pc.printf("TEST END\r\n\r\n"); return 0;