netemera prs

Dependencies:   mbed

Committer:
yabool2001
Date:
Tue Mar 26 18:06:18 2019 +0000
Revision:
2:9342176884e3
Parent:
1:db05ea2d0fe7
FRAM assembly test.; WEL bit toggle in FRAM Status Register

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yabool2001 0:9dffac13db39 1 #include "mbed.h"
yabool2001 0:9dffac13db39 2
yabool2001 1:db05ea2d0fe7 3 Serial serial ( PA_9 , NC );
yabool2001 0:9dffac13db39 4
yabool2001 2:9342176884e3 5 //SPI conf
yabool2001 2:9342176884e3 6 SPI spi ( PB_15 , PB_14 , PB_13 );
yabool2001 2:9342176884e3 7 //FRAM SPI CS conf
yabool2001 2:9342176884e3 8 DigitalOut fram_cs ( PB_12 );
yabool2001 2:9342176884e3 9
yabool2001 0:9dffac13db39 10 DigitalOut led_blue ( PA_5 );
yabool2001 0:9dffac13db39 11 DigitalOut led_red ( PA_8 );
yabool2001 0:9dffac13db39 12 DigitalOut led_orange ( PA_10 );
yabool2001 0:9dffac13db39 13
yabool2001 0:9dffac13db39 14 DigitalIn pulse ( PA_2 );
yabool2001 0:9dffac13db39 15 DigitalIn pulse_safe ( PB_5 );
yabool2001 0:9dffac13db39 16 DigitalIn flow_dir ( PB_9 );
yabool2001 0:9dffac13db39 17 DigitalIn case_open ( PA_3 );
yabool2001 0:9dffac13db39 18 DigitalIn sw1 ( PB_2 );
yabool2001 0:9dffac13db39 19 DigitalIn sw2 ( PB_6 );
yabool2001 0:9dffac13db39 20 DigitalIn sw3 ( PB_7 );
yabool2001 0:9dffac13db39 21
yabool2001 2:9342176884e3 22 int fram_rdsr = 0x01;
yabool2001 2:9342176884e3 23 int bit = 0;
yabool2001 2:9342176884e3 24
yabool2001 1:db05ea2d0fe7 25 InterruptIn int_pa_0 ( PA_0 );
yabool2001 0:9dffac13db39 26
yabool2001 0:9dffac13db39 27 // Toggle LED
yabool2001 0:9dffac13db39 28 void toggle_led ()
yabool2001 0:9dffac13db39 29 {
yabool2001 1:db05ea2d0fe7 30 serial .printf ( "int_pa_0 happened!:\n\r" );
yabool2001 1:db05ea2d0fe7 31 wait (0.1);
yabool2001 1:db05ea2d0fe7 32 if ( pulse == 1 ) led_blue = !led_blue;
yabool2001 1:db05ea2d0fe7 33 if ( pulse_safe == 1 ) led_red = !led_red;
yabool2001 1:db05ea2d0fe7 34 if ( flow_dir == 1 ) led_orange = !led_orange;
yabool2001 0:9dffac13db39 35 }
yabool2001 2:9342176884e3 36 void fram_cs_free ()
yabool2001 2:9342176884e3 37 {
yabool2001 2:9342176884e3 38 wait_us ( 10 ); fram_cs = 1; wait_us ( 10 );
yabool2001 2:9342176884e3 39 }
yabool2001 2:9342176884e3 40 void fram_cs_busy ()
yabool2001 2:9342176884e3 41 {
yabool2001 2:9342176884e3 42 wait_us ( 10 ); fram_cs = 0; wait_us ( 10 );
yabool2001 2:9342176884e3 43 }
yabool2001 0:9dffac13db39 44
yabool2001 0:9dffac13db39 45 int main() {
yabool2001 0:9dffac13db39 46
yabool2001 1:db05ea2d0fe7 47 //DIP switch pin set the mode to Pull Up
yabool2001 1:db05ea2d0fe7 48 sw1 .mode (PullUp);
yabool2001 1:db05ea2d0fe7 49 sw2 .mode (PullUp);
yabool2001 1:db05ea2d0fe7 50 sw3 .mode (PullUp);
yabool2001 0:9dffac13db39 51
yabool2001 1:db05ea2d0fe7 52 led_blue = 1;
yabool2001 1:db05ea2d0fe7 53 led_red = 1;
yabool2001 1:db05ea2d0fe7 54 led_orange = 1;
yabool2001 1:db05ea2d0fe7 55
yabool2001 2:9342176884e3 56 wait (1);
yabool2001 2:9342176884e3 57 // SPI conf
yabool2001 2:9342176884e3 58 spi.format ( 8 , 0 );
yabool2001 2:9342176884e3 59 spi.frequency ( 8000000 );
yabool2001 2:9342176884e3 60
yabool2001 2:9342176884e3 61 // FRAM RDSR ( Read Status Register )
yabool2001 2:9342176884e3 62 fram_cs_busy ();
yabool2001 2:9342176884e3 63 spi.write ( 0x05 );
yabool2001 2:9342176884e3 64 fram_rdsr = spi.write ( 0x00 );
yabool2001 2:9342176884e3 65 fram_cs_free ();
yabool2001 2:9342176884e3 66 serial.printf ( "FRAM RDSR = 0x%X\n\r" , fram_rdsr );
yabool2001 2:9342176884e3 67 bit = ( fram_rdsr >> 1 ) & 1U;
yabool2001 2:9342176884e3 68 serial.printf ( "FRAM RDSR WEL bit = %u\n\r" , bit );
yabool2001 2:9342176884e3 69
yabool2001 2:9342176884e3 70 // FRAM WRSR ( Write Status Register ) Toggle WEL bit
yabool2001 2:9342176884e3 71 fram_rdsr ^= 1UL << 1;
yabool2001 2:9342176884e3 72 fram_cs_busy ();
yabool2001 2:9342176884e3 73 if ( !bit )
yabool2001 2:9342176884e3 74 spi.write ( 0x06 ); // Set Write Enable Latch
yabool2001 2:9342176884e3 75 spi.write ( 0x01 ); // Write Status Register
yabool2001 2:9342176884e3 76 spi.write ( fram_rdsr ); // Write toggled WEL bit
yabool2001 2:9342176884e3 77 fram_cs_free ();
yabool2001 2:9342176884e3 78 serial.printf ( "Toggle WEL bit");
yabool2001 2:9342176884e3 79
yabool2001 2:9342176884e3 80 // FRAM RDSR ( Read Status Register )
yabool2001 2:9342176884e3 81 fram_cs_busy ();
yabool2001 2:9342176884e3 82 spi.write ( 0x05 );
yabool2001 2:9342176884e3 83 fram_rdsr = spi.write ( 0x00 );
yabool2001 2:9342176884e3 84 fram_cs_free ();
yabool2001 2:9342176884e3 85 serial.printf ( "FRAM RDSR = 0x%X\n\r" , fram_rdsr );
yabool2001 2:9342176884e3 86 bit = ( fram_rdsr >> 1 ) & 1U;
yabool2001 2:9342176884e3 87 serial.printf ( "FRAM RDSR WEL bit = %u\n\r" , bit );
yabool2001 2:9342176884e3 88
yabool2001 1:db05ea2d0fe7 89 // Change LEDs blinking frequency when pulse
yabool2001 1:db05ea2d0fe7 90 int_pa_0.rise ( &toggle_led );
yabool2001 0:9dffac13db39 91
yabool2001 0:9dffac13db39 92 while ( 1 )
yabool2001 0:9dffac13db39 93 {
yabool2001 2:9342176884e3 94 wait ( 5 );
yabool2001 1:db05ea2d0fe7 95
yabool2001 0:9dffac13db39 96 serial.printf ( "DIP switch status:\n\r" );
yabool2001 1:db05ea2d0fe7 97 ( sw1 ) ? serial .printf ( "SW1 = 1\n\r" ) : serial .printf ( "SW1 = 0\n\r" );
yabool2001 1:db05ea2d0fe7 98 ( sw2 ) ? serial .printf ( "SW2 = 1\n\r" ) : serial .printf ( "SW2 = 0\n\r" );
yabool2001 1:db05ea2d0fe7 99 ( sw3 ) ? serial .printf ( "SW3 = 1\n\r" ) : serial .printf ( "SW3 = 0\n\r" );
yabool2001 1:db05ea2d0fe7 100
yabool2001 1:db05ea2d0fe7 101 serial.printf ( "Pulse status:\n\r" );
yabool2001 1:db05ea2d0fe7 102 ( pulse ) ? serial .printf ( "pulse = 1\n\r" ) : serial .printf ( "pulse = 0\n\r" );
yabool2001 1:db05ea2d0fe7 103 ( pulse_safe ) ? serial .printf ( "pulse_safe = 1\n\r" ) : serial .printf ( "pulse_safe = 0\n\r" );
yabool2001 1:db05ea2d0fe7 104 ( flow_dir ) ? serial .printf ( "flow_dir = 1\n\r" ) : serial .printf ( "flow_dir = 0\n\r" );
yabool2001 0:9dffac13db39 105 }
yabool2001 0:9dffac13db39 106 }