test

Committer:
elijahsj
Date:
Mon Nov 09 00:02:47 2020 -0500
Revision:
1:8a094db1347f
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elijahsj 1:8a094db1347f 1 /* mbed Microcontroller Library
elijahsj 1:8a094db1347f 2 *******************************************************************************
elijahsj 1:8a094db1347f 3 * Copyright (c) 2015, STMicroelectronics
elijahsj 1:8a094db1347f 4 * All rights reserved.
elijahsj 1:8a094db1347f 5 *
elijahsj 1:8a094db1347f 6 * Redistribution and use in source and binary forms, with or without
elijahsj 1:8a094db1347f 7 * modification, are permitted provided that the following conditions are met:
elijahsj 1:8a094db1347f 8 *
elijahsj 1:8a094db1347f 9 * 1. Redistributions of source code must retain the above copyright notice,
elijahsj 1:8a094db1347f 10 * this list of conditions and the following disclaimer.
elijahsj 1:8a094db1347f 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
elijahsj 1:8a094db1347f 12 * this list of conditions and the following disclaimer in the documentation
elijahsj 1:8a094db1347f 13 * and/or other materials provided with the distribution.
elijahsj 1:8a094db1347f 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
elijahsj 1:8a094db1347f 15 * may be used to endorse or promote products derived from this software
elijahsj 1:8a094db1347f 16 * without specific prior written permission.
elijahsj 1:8a094db1347f 17 *
elijahsj 1:8a094db1347f 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
elijahsj 1:8a094db1347f 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
elijahsj 1:8a094db1347f 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
elijahsj 1:8a094db1347f 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
elijahsj 1:8a094db1347f 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
elijahsj 1:8a094db1347f 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
elijahsj 1:8a094db1347f 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
elijahsj 1:8a094db1347f 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
elijahsj 1:8a094db1347f 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
elijahsj 1:8a094db1347f 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
elijahsj 1:8a094db1347f 28 *******************************************************************************
elijahsj 1:8a094db1347f 29 */
elijahsj 1:8a094db1347f 30 #ifndef MBED_I2C_DEVICE_H
elijahsj 1:8a094db1347f 31 #define MBED_I2C_DEVICE_H
elijahsj 1:8a094db1347f 32
elijahsj 1:8a094db1347f 33 #include "cmsis.h"
elijahsj 1:8a094db1347f 34
elijahsj 1:8a094db1347f 35 #ifdef __cplusplus
elijahsj 1:8a094db1347f 36 extern "C" {
elijahsj 1:8a094db1347f 37 #endif
elijahsj 1:8a094db1347f 38
elijahsj 1:8a094db1347f 39 #ifdef DEVICE_I2C
elijahsj 1:8a094db1347f 40
elijahsj 1:8a094db1347f 41 #define I2C_IP_VERSION_V2
elijahsj 1:8a094db1347f 42
elijahsj 1:8a094db1347f 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)
elijahsj 1:8a094db1347f 44
elijahsj 1:8a094db1347f 45 /* Family specifc settings for clock source */
elijahsj 1:8a094db1347f 46 #define I2CAPI_I2C1_CLKSRC RCC_I2C1CLKSOURCE_SYSCLK
elijahsj 1:8a094db1347f 47 #define I2CAPI_I2C2_CLKSRC RCC_I2C2CLKSOURCE_SYSCLK
elijahsj 1:8a094db1347f 48 #define I2CAPI_I2C3_CLKSRC RCC_I2C3CLKSOURCE_SYSCLK
elijahsj 1:8a094db1347f 49
elijahsj 1:8a094db1347f 50 /* Provide the suitable timing depending on requested frequencie */
elijahsj 1:8a094db1347f 51 static inline uint32_t get_i2c_timing(int hz)
elijahsj 1:8a094db1347f 52 {
elijahsj 1:8a094db1347f 53 uint32_t tim = 0;
elijahsj 1:8a094db1347f 54 /*
elijahsj 1:8a094db1347f 55 Values calculated with I2C_Timing_Configuration_V1.0.1.xls file (see AN4235)
elijahsj 1:8a094db1347f 56 * Standard mode (up to 100 kHz)
elijahsj 1:8a094db1347f 57 * Fast Mode (up to 400 kHz)
elijahsj 1:8a094db1347f 58 * Fast Mode Plus (up to 1 MHz)
elijahsj 1:8a094db1347f 59 Below values obtained with:
elijahsj 1:8a094db1347f 60 - I2C clock source = 64 MHz (System Clock w/ HSI) or 72 (System Clock w/ HSE)
elijahsj 1:8a094db1347f 61 - Analog filter delay = ON
elijahsj 1:8a094db1347f 62 - Digital filter coefficient = 0
elijahsj 1:8a094db1347f 63 */
elijahsj 1:8a094db1347f 64 if (SystemCoreClock == 64000000) {
elijahsj 1:8a094db1347f 65 switch (hz) {
elijahsj 1:8a094db1347f 66 case 100000:
elijahsj 1:8a094db1347f 67 tim = 0x10B17DB4; // Standard mode with Rise time = 120ns, Fall time = 120ns
elijahsj 1:8a094db1347f 68 break;
elijahsj 1:8a094db1347f 69 case 400000:
elijahsj 1:8a094db1347f 70 tim = 0x00E22163; // Fast Mode with Rise time = 120ns, Fall time = 120ns
elijahsj 1:8a094db1347f 71 break;
elijahsj 1:8a094db1347f 72 case 1000000:
elijahsj 1:8a094db1347f 73 tim = 0x00A00D1E; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns
elijahsj 1:8a094db1347f 74 break;
elijahsj 1:8a094db1347f 75 default:
elijahsj 1:8a094db1347f 76 break;
elijahsj 1:8a094db1347f 77 }
elijahsj 1:8a094db1347f 78 } else if (SystemCoreClock == 72000000) {
elijahsj 1:8a094db1347f 79 switch (hz) {
elijahsj 1:8a094db1347f 80 case 100000:
elijahsj 1:8a094db1347f 81 tim = 0x10D28DCB; // Standard mode with Rise time = 120ns, Fall time = 120ns
elijahsj 1:8a094db1347f 82 break;
elijahsj 1:8a094db1347f 83 case 400000:
elijahsj 1:8a094db1347f 84 tim = 0x00F32571; // Fast Mode with Rise time = 120ns, Fall time = 120ns
elijahsj 1:8a094db1347f 85 break;
elijahsj 1:8a094db1347f 86 case 1000000:
elijahsj 1:8a094db1347f 87 tim = 0x00C00D24; // Fast Mode Plus with Rise time = 120ns, Fall time = 10ns
elijahsj 1:8a094db1347f 88 break;
elijahsj 1:8a094db1347f 89 default:
elijahsj 1:8a094db1347f 90 break;
elijahsj 1:8a094db1347f 91 }
elijahsj 1:8a094db1347f 92 }
elijahsj 1:8a094db1347f 93 return tim;
elijahsj 1:8a094db1347f 94 }
elijahsj 1:8a094db1347f 95
elijahsj 1:8a094db1347f 96 #ifdef __cplusplus
elijahsj 1:8a094db1347f 97 }
elijahsj 1:8a094db1347f 98 #endif
elijahsj 1:8a094db1347f 99
elijahsj 1:8a094db1347f 100 #endif // DEVICE_I2C
elijahsj 1:8a094db1347f 101
elijahsj 1:8a094db1347f 102 #endif