mbed library sources

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
mbed_official
Date:
Thu May 15 13:45:07 2014 +0100
Parent:
189:4502ef52f909
Child:
191:69dccf9d09a7
Commit message:
Synchronized with git revision 6bc9b93a40580f033430e21cbdc4a637c9f98523

Full URL: https://github.com/mbedmicro/mbed/commit/6bc9b93a40580f033430e21cbdc4a637c9f98523/

Changed in this revision

targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/device.h Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c Show annotated file Show diff for this revision Revisions of this file
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/device.h	Wed May 14 14:00:07 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/device.h	Thu May 15 13:45:07 2014 +0100
@@ -42,10 +42,10 @@
 #define DEVICE_SERIAL           1
 
 #define DEVICE_I2C              1
-#define DEVICE_I2CSLAVE         0 // Not yet supported
+#define DEVICE_I2CSLAVE         1
 
 #define DEVICE_SPI              1
-#define DEVICE_SPISLAVE         0 // Not yet supported
+#define DEVICE_SPISLAVE         1
 
 #define DEVICE_RTC              1
 
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c	Wed May 14 14:00:07 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/i2c_api.c	Thu May 15 13:45:07 2014 +0100
@@ -313,7 +313,44 @@
 #define WriteAddressed 3 // the master is writing to this slave (slave = receiver)
 
 int i2c_slave_receive(i2c_t *obj) {
-    return (0);
+    int retValue = NoData;
+    uint32_t event;
+    I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
+
+    event = I2C_GetLastEvent( i2c );
+    if(event != 0)
+    {
+        switch(event){
+            case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:
+                retValue = WriteAddressed;
+                break;
+            case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED:
+                retValue = ReadAddressed;
+                break;
+            case I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED:
+                retValue = WriteGeneral;
+                break;
+            default:
+                retValue = NoData;
+                break;
+        }
+
+        // clear ADDR 
+        if((retValue == WriteAddressed) || (retValue == ReadAddressed)){
+            i2c->SR1;// read status register 1
+            i2c->SR2;// read status register 2
+        }
+        // clear stopf
+        if(I2C_GetFlagStatus(i2c, I2C_FLAG_STOPF) == SET) {
+            i2c->SR1;// read status register 1
+            I2C_Cmd(i2c,  ENABLE);    
+        }
+        // clear AF
+        if(I2C_GetFlagStatus(i2c, I2C_FLAG_AF) == SET) {
+            I2C_ClearFlag(i2c, I2C_FLAG_AF);
+        }        
+    }
+    return(retValue);
 }
 
 int i2c_slave_read(i2c_t *obj, char *data, int length) {
--- a/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c	Wed May 14 14:00:07 2014 +0100
+++ b/targets/hal/TARGET_STM/TARGET_NUCLEO_L152RE/spi_api.c	Thu May 15 13:45:07 2014 +0100
@@ -138,7 +138,7 @@
     } else { // Slave
         pinmap_pinout(ssel, PinMap_SPI_SSEL);
         obj->mode = SPI_Mode_Slave;
-        obj->nss = SPI_NSS_Soft;
+        obj->nss = SPI_NSS_Hard;
     }
 
     init_spi(obj);
@@ -270,7 +270,8 @@
 }
 
 int spi_slave_receive(spi_t *obj) {
-    return (ssp_readable(obj) && !ssp_busy(obj)) ? (1) : (0);
+    //return (ssp_readable(obj) && !ssp_busy(obj)) ? (1) : (0); // initial code
+    return (ssp_readable(obj)) ? (1) : (0); // works better like this
 };
 
 int spi_slave_read(spi_t *obj) {