Chihiro H
/
Microchip23K256_demo
Microchip 23K256 (SPI SRAM) sample code for https://www.switch-science.com/catalog/1072/ module.
Diff: main.cpp
- Revision:
- 3:65a33de8fa08
- Parent:
- 2:0248049e65f1
- Child:
- 4:b1021974c3e7
--- a/main.cpp Sat Nov 01 13:58:50 2014 +0000 +++ b/main.cpp Sun Nov 02 03:22:21 2014 +0000 @@ -1,9 +1,15 @@ /* * 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 - * - + * - Microchip 23K256 + * - SRAM + * - SPI 20MHz + * - Intersil ISL29125 + * - Red/Green/Blue Color Light Sensor + * - I2C 500KHz, address = x100 0100, hard-wires + * - TAOS TSL2561 + * - LUX Sensor + * - I2C 400kHz, address = x010 1001 (ADDR-GND), x011 1011 (ADDR-Float), x100 1001 (ADDR-VDD) + * - A/D conversion time: 12ms min, 100ms typ, 400ms max. */ #include "mbed.h" @@ -11,32 +17,37 @@ /** Serial port for DEBUG */ Serial pc(USBTX, USBRX); -InterruptIn mybutton(USER_BUTTON); - -/** ユーザーボタンが押されたらtrue */ -volatile bool is_pressed = false; - -/** - * USERボタン 割り込みハンドラ - */ -void -pressed() { - is_pressed = true; -} +DigitalIn user_button(USER_BUTTON); /** * USERボタンが押されるまで待つ。 */ void wait_until_user_button_pressed() { - while (!is_pressed) { + while (user_button) { __nop(); } - is_pressed = false; pc.printf("USER button is pressed\r\n"); } /** */ +//DigitalOut user_led(LED1); // SPI1 SCK + +/** + * + * @param[in] interval_sec 点滅間隔(単位=秒) + * @param[in] times 点滅回数 +*/ +//void +//flash_led(const float interval_sec, const uint16_t times) { +// user_led = 1; +// for (uint16_t i = 0; i < times * 2; ++i) { +// wait(interval_sec); +// user_led = !user_led; +// } +//} + +/** */ SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK); /** */ @@ -323,30 +334,34 @@ int main() { - mybutton.fall(&pressed); + pc.printf("CPU SystemCoreClock is %.2f MHz\r\n", (float)SystemCoreClock/1.0e6f); - wait_until_user_button_pressed(); - - // initialize + // initialize SPI spi.format(8, 0); // 8bit, mode=0 spi.frequency(20 * 1000 * 1000); // max 20MHz negate_CS(); // test - pc.printf("TEST START\r\n"); - + pc.printf("\r\npush user button to start: try_single_byte_access\r\n"); wait_until_user_button_pressed(); try_single_byte_access(); + pc.printf("\r\npush user button to start: try_byte_access\r\n"); wait_until_user_button_pressed(); try_byte_access(); + pc.printf("\r\npush user button to start: try_page_access\r\n"); + wait_until_user_button_pressed(); try_page_access(); + pc.printf("\r\npush user button to start: try_sequential_access\r\n"); wait_until_user_button_pressed(); try_sequential_access(); - pc.printf("TEST END\r\n\r\n"); + pc.printf("\r\nTEST END\r\n\r\n"); - return 0; + for(;;) { +// flash_led(0.125, 8); +// flash_led(0.50, 2); + } }