7,14 → 7,14 |
// + FOR NON COMMERCIAL USE ONLY |
// + www.MikroKopter.com |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
// + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
// + bzgl. der Nutzungsbedingungen aufzunehmen. |
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
// + Verkauf von Luftbildaufnahmen, usw. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
25,21 → 25,21 |
// + Benutzung auf eigene Gefahr |
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
// + mit unserer Zustimmung zulässig |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
// + this list of conditions and the following disclaimer. |
// + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
// + from this software without specific prior written permission. |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
// + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
// + for non-commercial use (directly or indirectly) |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
// + with our written permission |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
// + clearly linked as origin |
// + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
// |
// + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
52,7 → 52,7 |
// + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
// + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
// + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// + POSSIBILITY OF SUCH DAMAGE. |
// + POSSIBILITY OF SUCH DAMAGE. |
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
#include "main.h" |
|
64,7 → 64,7 |
struct str_I2C_Heading I2C_Heading; |
struct str_I2C_WriteNickRoll I2C_WriteNickRoll; |
struct str_I2C_Mag I2C_Mag; |
struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM; |
struct str_I2C_EEPROM I2C_ReadEEPROM, I2C_WriteEEPROM; |
struct str_I2C_Version I2C_Version; |
struct str_I2C_WriteCal I2C_WriteCal; |
u8 CompassUpdateActiv = 0; |
76,7 → 76,7 |
{ |
I2C_InitTypeDef I2C_Struct; |
GPIO_InitTypeDef GPIO_Struct; |
|
|
SerialPutString("I2C init..."); |
SCU_APBPeriphClockConfig(__I2C1,ENABLE); |
I2C_DeInit(I2C1); |
92,23 → 92,23 |
I2C_Struct.I2C_CLKSpeed = 20000; |
I2C_Struct.I2C_OwnAddress = I2C_SLAVE_ADDRESS; |
I2C_Init(I2C1, &I2C_Struct); |
|
|
I2C_Cmd(I2C1, ENABLE); |
I2C_ITConfig(I2C1, ENABLE); |
|
|
VIC_Config(I2C1_ITLine,VIC_IRQ , 8); |
VIC_ITCmd(I2C1_ITLine, ENABLE); |
|
I2C_Heading.Heading = 0; |
SerialPutString("ok\n\r"); |
|
|
|
|
} |
|
//-------------------------------------------------------------- |
void I2C1_IRQHandler(void) |
{ |
|
|
switch (I2C_GetLastEvent(I2C1)) |
{ |
case I2C_EVENT_MASTER_MODE_SELECT: // EV5 |
122,7 → 122,7 |
// Clear EV6 by set again the PE bit |
I2C1->CR |= 0x20; |
if (I2C_Direction == I2C_MODE_TRANSMITTER) |
{ |
{ |
I2C_SendData(I2C1, I2C_Command);//EV8 just after EV6 |
} |
break; |
145,23 → 145,23 |
Tx_Idx++; |
} |
break; |
|
|
case I2C_EVENT_MASTER_BYTE_RECEIVED: // EV7 |
DebugOut.Analog[16]++; |
//if (Rx_Idx == 1) DebugOut.Analog[19] = I2C_RxBuffer[0]; |
if (Rx_Idx < I2C_RxBufferSize) |
{ I2C_RxBuffer[Rx_Idx] = I2C_ReceiveData(I2C1); |
|
|
} else I2C_ReceiveData(I2C1); |
|
|
Rx_Idx++; |
if ( Rx_Idx == I2C_RxBufferSize-2 ) |
if ( Rx_Idx == I2C_RxBufferSize+1 ) |
{ |
I2C_AcknowledgeConfig (I2C1, DISABLE); |
} |
if ( Rx_Idx == I2C_RxBufferSize -1 ) |
} |
if ( Rx_Idx == I2C_RxBufferSize+2 ) |
{ |
I2C_GenerateSTOP(I2C1, ENABLE); |
I2C_GenerateSTOP(I2C1, ENABLE); |
if (I2C_Command == I2C_CMD_READ_HEADING) CompassUpdateActiv = 0; |
} |
break; |
168,13 → 168,13 |
|
default: |
break; |
} |
} |
} |
//---------------------------------------------------------------- |
void SendI2C_Command(u8 command) |
{ |
I2C_Command = command; |
//I2C_GenerateSTOP(I2C1, ENABLE); |
//I2C_GenerateSTOP(I2C1, ENABLE); |
|
switch (command) |
{ |
185,13 → 185,13 |
break; |
case I2C_CMD_WRITE_EEPROM: |
I2C_RxBufferSize = 0; |
I2C_TxBuffer = (u8 *)&I2C_WriteEEPROM; |
I2C_TxBuffer = (u8 *)&I2C_WriteEEPROM; |
I2C_TxBufferSize = sizeof(I2C_WriteEEPROM); |
break; |
case I2C_CMD_WRITE_CAL: |
I2C_RxBufferSize = 0; |
I2C_WriteCal.CalByte = CompassCalState; |
I2C_TxBuffer = (u8 *)&I2C_WriteCal; |
I2C_WriteCal.CalByte = CompassCalState; |
I2C_TxBuffer = (u8 *)&I2C_WriteCal; |
I2C_TxBufferSize = sizeof(I2C_WriteCal); |
break; |
case I2C_CMD_READ_EEPROM: |
209,20 → 209,21 |
CompassUpdateActiv = 1; |
I2C_RxBuffer = (u8 *)&I2C_Heading; |
I2C_RxBufferSize = sizeof(I2C_Heading); |
I2C_TxBuffer = (u8 *)&I2C_WriteNickRoll; |
I2C_TxBuffer = (u8 *)&I2C_WriteNickRoll; |
I2C_TxBufferSize = sizeof(I2C_WriteNickRoll); |
break; |
|
} |
/* |
if (I2C_RxBufferSize > 0) |
{ |
I2C_RxBufferSize++; |
if (I2C_RxBufferSize < 3) I2C_RxBufferSize = 3; |
} |
}*/ |
|
I2C_AcknowledgeConfig (I2C1, ENABLE); |
I2C_Direction = I2C_MODE_TRANSMITTER; |
|
|
I2C_GenerateStart(I2C1, ENABLE); |
|
} |