Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of _8_CONV_1_SLAVE by
Revision 6:b9578f756c9c, committed 2015-12-17
- Comitter:
- marcus255
- Date:
- Thu Dec 17 18:33:21 2015 +0000
- Parent:
- 5:d622f8a4a016
- Commit message:
- Address discovering functionality added and works fine
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Dec 17 00:03:01 2015 +0000
+++ b/main.cpp Thu Dec 17 18:33:21 2015 +0000
@@ -1,9 +1,15 @@
// Conv1 Slave
#include "main.h"
-
+ volatile int i = 0;
+ volatile int discovered_address = 0;
int main()
{
init();
+ int prev_state = 1;
+ int temp_state;
+ uint8_t address = 0;
+
+ int states[9];
while (1) {}
}
@@ -61,39 +67,34 @@
void init(void)
{
device.baud(921600);
- SDA_interrupt.fall(&on_SDA_falling_slope_interrupt);
+ SCL_interrupt.rise(&on_SCL_rising_slope_interrupt);
}
-void on_SDA_falling_slope_interrupt(void)
+void on_SCL_rising_slope_interrupt(void)
{
- SDA_interrupt.disable_irq();
- int prev_state = 1;
- int temp_state;
- uint8_t address = 0;
- for (int i = 7; i >= 0; i--) //for every clock cycle in frame
- {
- while(1) //sample CLK line state
+
+ //=(char)SDA_state
+ if (i<9)
{
- if ((temp_state = SCL_state) == prev_state)
- continue;
- else
- {
- if (SDA_state == 1)
- address |= (0x01 << i);
- prev_state = temp_state;
- //device.putc((char)SDA_state);
- break;
- }
+ if (SDA_state)
+ discovered_address |= (0x01<<(7-i));
+ i++;
}
+ else
+ {
+ SCL_interrupt.disable_irq();
+ device.putc((char)discovered_address);
+ i = 0;
+ discovered_address = 0;
}
-
+
// now we (probably) know the Slave address, so we can initialize i2c bus
// and set this Conv as Conv1 and send info to second Conv to act as Conv2
//device.putc(SET_CONV2_FUNCT);
- device.putc(address);
+ //device.putc(address);
//init_I2C(address, 100000);
- SDA_interrupt.enable_irq();
+ //SDA_interrupt.enable_irq();
}
void init_I2C(char addr, int freq)
--- a/main.h Thu Dec 17 00:03:01 2015 +0000 +++ b/main.h Thu Dec 17 18:33:21 2015 +0000 @@ -16,9 +16,8 @@ I2CSlave slave(PTB4, PTB3); Serial device(USBTX, USBRX); InterruptIn SDA_interrupt(PTB7); -//InterruptIn SCL_interrupt(PTB3); +InterruptIn SCL_interrupt(PTA12); DigitalIn SDA_state(PTB6); -DigitalIn SCL_state(PTB3); // same as I2C CLK //char msg[] = "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm"; char buffer; @@ -27,6 +26,6 @@ void i2cStart(void); void init(void); void init_I2C(char, int); -void on_SDA_falling_slope_interrupt(void); +void on_SCL_rising_slope_interrupt(void); #endif \ No newline at end of file
