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.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
targets/TARGET_STM/TARGET_STM32F7/i2c_device.h@0:098463de4c5d, 2017-01-25 (annotated)
- Committer:
- group-onsemi
- Date:
- Wed Jan 25 20:34:15 2017 +0000
- Revision:
- 0:098463de4c5d
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
group-onsemi | 0:098463de4c5d | 1 | /* mbed Microcontroller Library |
group-onsemi | 0:098463de4c5d | 2 | ******************************************************************************* |
group-onsemi | 0:098463de4c5d | 3 | * Copyright (c) 2015, STMicroelectronics |
group-onsemi | 0:098463de4c5d | 4 | * All rights reserved. |
group-onsemi | 0:098463de4c5d | 5 | * |
group-onsemi | 0:098463de4c5d | 6 | * Redistribution and use in source and binary forms, with or without |
group-onsemi | 0:098463de4c5d | 7 | * modification, are permitted provided that the following conditions are met: |
group-onsemi | 0:098463de4c5d | 8 | * |
group-onsemi | 0:098463de4c5d | 9 | * 1. Redistributions of source code must retain the above copyright notice, |
group-onsemi | 0:098463de4c5d | 10 | * this list of conditions and the following disclaimer. |
group-onsemi | 0:098463de4c5d | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
group-onsemi | 0:098463de4c5d | 12 | * this list of conditions and the following disclaimer in the documentation |
group-onsemi | 0:098463de4c5d | 13 | * and/or other materials provided with the distribution. |
group-onsemi | 0:098463de4c5d | 14 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
group-onsemi | 0:098463de4c5d | 15 | * may be used to endorse or promote products derived from this software |
group-onsemi | 0:098463de4c5d | 16 | * without specific prior written permission. |
group-onsemi | 0:098463de4c5d | 17 | * |
group-onsemi | 0:098463de4c5d | 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
group-onsemi | 0:098463de4c5d | 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
group-onsemi | 0:098463de4c5d | 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
group-onsemi | 0:098463de4c5d | 21 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
group-onsemi | 0:098463de4c5d | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
group-onsemi | 0:098463de4c5d | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
group-onsemi | 0:098463de4c5d | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
group-onsemi | 0:098463de4c5d | 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
group-onsemi | 0:098463de4c5d | 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
group-onsemi | 0:098463de4c5d | 27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
group-onsemi | 0:098463de4c5d | 28 | ******************************************************************************* |
group-onsemi | 0:098463de4c5d | 29 | */ |
group-onsemi | 0:098463de4c5d | 30 | #ifndef MBED_I2C_DEVICE_H |
group-onsemi | 0:098463de4c5d | 31 | #define MBED_I2C_DEVICE_H |
group-onsemi | 0:098463de4c5d | 32 | |
group-onsemi | 0:098463de4c5d | 33 | #include "cmsis.h" |
group-onsemi | 0:098463de4c5d | 34 | |
group-onsemi | 0:098463de4c5d | 35 | #ifdef __cplusplus |
group-onsemi | 0:098463de4c5d | 36 | extern "C" { |
group-onsemi | 0:098463de4c5d | 37 | #endif |
group-onsemi | 0:098463de4c5d | 38 | |
group-onsemi | 0:098463de4c5d | 39 | #ifdef DEVICE_I2C |
group-onsemi | 0:098463de4c5d | 40 | |
group-onsemi | 0:098463de4c5d | 41 | #define I2C_IP_VERSION_V2 |
group-onsemi | 0:098463de4c5d | 42 | |
group-onsemi | 0:098463de4c5d | 43 | #define I2C_IT_ALL (I2C_IT_ERRI|I2C_IT_TCI|I2C_IT_STOPI|I2C_IT_NACKI|I2C_IT_ADDRI|I2C_IT_RXI|I2C_IT_TXI) |
group-onsemi | 0:098463de4c5d | 44 | |
group-onsemi | 0:098463de4c5d | 45 | /* Family specifc settings for clock source */ |
group-onsemi | 0:098463de4c5d | 46 | #define I2CAPI_I2C1_CLKSRC RCC_I2C1CLKSOURCE_PCLK1 |
group-onsemi | 0:098463de4c5d | 47 | #define I2CAPI_I2C2_CLKSRC RCC_I2C2CLKSOURCE_PCLK1 |
group-onsemi | 0:098463de4c5d | 48 | #define I2CAPI_I2C3_CLKSRC RCC_I2C3CLKSOURCE_PCLK1 |
group-onsemi | 0:098463de4c5d | 49 | #define I2CAPI_I2C4_CLKSRC RCC_I2C4CLKSOURCE_PCLK1 |
group-onsemi | 0:098463de4c5d | 50 | |
group-onsemi | 0:098463de4c5d | 51 | /* Provide the suitable timing depending on requested frequencie */ |
group-onsemi | 0:098463de4c5d | 52 | static inline uint32_t get_i2c_timing(int hz) |
group-onsemi | 0:098463de4c5d | 53 | { |
group-onsemi | 0:098463de4c5d | 54 | uint32_t tim = 0; |
group-onsemi | 0:098463de4c5d | 55 | /* |
group-onsemi | 0:098463de4c5d | 56 | Values calculated with I2C_Timing_Configuration tool (excel file) |
group-onsemi | 0:098463de4c5d | 57 | * Standard mode (up to 100 kHz) |
group-onsemi | 0:098463de4c5d | 58 | * Fast Mode (up to 400 kHz) |
group-onsemi | 0:098463de4c5d | 59 | * Fast Mode Plus (up to 1 MHz) |
group-onsemi | 0:098463de4c5d | 60 | Below values obtained with: |
group-onsemi | 0:098463de4c5d | 61 | - I2Cx clock source = APB1CLK = 54 MHz |
group-onsemi | 0:098463de4c5d | 62 | - Analog filter delay = ON |
group-onsemi | 0:098463de4c5d | 63 | - Digital filter coefficient = 0 |
group-onsemi | 0:098463de4c5d | 64 | */ |
group-onsemi | 0:098463de4c5d | 65 | switch (hz) { |
group-onsemi | 0:098463de4c5d | 66 | case 100000: |
group-onsemi | 0:098463de4c5d | 67 | tim = 0x10916998; // Standard mode with Rise time = 120ns, Fall time = 120ns |
group-onsemi | 0:098463de4c5d | 68 | break; |
group-onsemi | 0:098463de4c5d | 69 | case 400000: |
group-onsemi | 0:098463de4c5d | 70 | tim = 0x00B11B54; // Fast Mode with Rise time = 120ns, Fall time = 120ns |
group-onsemi | 0:098463de4c5d | 71 | break; |
group-onsemi | 0:098463de4c5d | 72 | case 1000000: |
group-onsemi | 0:098463de4c5d | 73 | tim = 0x0090091B; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns |
group-onsemi | 0:098463de4c5d | 74 | break; |
group-onsemi | 0:098463de4c5d | 75 | default: |
group-onsemi | 0:098463de4c5d | 76 | break; |
group-onsemi | 0:098463de4c5d | 77 | } |
group-onsemi | 0:098463de4c5d | 78 | return tim; |
group-onsemi | 0:098463de4c5d | 79 | } |
group-onsemi | 0:098463de4c5d | 80 | |
group-onsemi | 0:098463de4c5d | 81 | #ifdef __cplusplus |
group-onsemi | 0:098463de4c5d | 82 | } |
group-onsemi | 0:098463de4c5d | 83 | #endif |
group-onsemi | 0:098463de4c5d | 84 | |
group-onsemi | 0:098463de4c5d | 85 | #endif // DEVICE_I2C |
group-onsemi | 0:098463de4c5d | 86 | |
group-onsemi | 0:098463de4c5d | 87 | #endif |