netemera prs

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
yabool2001
Date:
Tue Mar 26 18:06:18 2019 +0000
Parent:
1:db05ea2d0fe7
Commit message:
FRAM assembly test.; WEL bit toggle in FRAM Status Register

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Mar 26 10:01:53 2019 +0000
+++ b/main.cpp	Tue Mar 26 18:06:18 2019 +0000
@@ -2,6 +2,11 @@
 
 Serial serial ( PA_9 , NC );
 
+//SPI conf
+SPI spi ( PB_15 , PB_14 , PB_13 );
+//FRAM SPI CS conf
+DigitalOut fram_cs ( PB_12 );
+
 DigitalOut led_blue ( PA_5 );
 DigitalOut led_red ( PA_8 );
 DigitalOut led_orange ( PA_10 );
@@ -14,6 +19,9 @@
 DigitalIn sw2 ( PB_6 );
 DigitalIn sw3 ( PB_7 );
 
+int fram_rdsr = 0x01;
+int bit = 0;
+
 InterruptIn int_pa_0 ( PA_0 );
 
 // Toggle LED
@@ -25,6 +33,14 @@
     if ( pulse_safe == 1 )  led_red = !led_red;
     if ( flow_dir == 1 )    led_orange = !led_orange;
 }
+void fram_cs_free ()
+{
+    wait_us ( 10 ); fram_cs = 1; wait_us ( 10 );
+}
+void fram_cs_busy ()
+{
+    wait_us ( 10 ); fram_cs = 0; wait_us ( 10 );
+}
 
 int main() {
 
@@ -37,12 +53,45 @@
     led_red     = 1;
     led_orange  = 1;
 
+    wait (1);
+    // SPI conf
+    spi.format ( 8 , 0 );
+    spi.frequency ( 8000000 );
+
+    // FRAM RDSR ( Read Status Register )
+    fram_cs_busy ();
+    spi.write ( 0x05 );
+    fram_rdsr = spi.write ( 0x00 );
+    fram_cs_free ();
+    serial.printf ( "FRAM RDSR = 0x%X\n\r" , fram_rdsr );
+    bit = ( fram_rdsr >> 1 ) & 1U;
+    serial.printf ( "FRAM RDSR WEL bit = %u\n\r" , bit );
+    
+    // FRAM WRSR ( Write Status Register ) Toggle WEL bit
+    fram_rdsr ^= 1UL << 1;
+    fram_cs_busy ();
+    if ( !bit )
+        spi.write ( 0x06 ); // Set Write Enable Latch
+    spi.write ( 0x01 ); // Write Status Register
+    spi.write ( fram_rdsr ); // Write toggled WEL bit
+    fram_cs_free ();
+    serial.printf ( "Toggle WEL bit");
+    
+    // FRAM RDSR ( Read Status Register )
+    fram_cs_busy ();
+    spi.write ( 0x05 );
+    fram_rdsr = spi.write ( 0x00 );
+    fram_cs_free ();
+    serial.printf ( "FRAM RDSR = 0x%X\n\r" , fram_rdsr );
+    bit = ( fram_rdsr >> 1 ) & 1U;
+    serial.printf ( "FRAM RDSR WEL bit = %u\n\r" , bit );
+
     // Change LEDs blinking frequency when pulse
     int_pa_0.rise ( &toggle_led );
 
     while ( 1 )
     {
-        wait ( 0.5 );
+        wait ( 5 );
 
         serial.printf ( "DIP switch status:\n\r" );
         ( sw1 ) ? serial .printf ( "SW1 = 1\n\r" ) : serial .printf ( "SW1 = 0\n\r" );