The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
<>
Date:
Wed Apr 12 16:07:08 2017 +0100
Revision:
140:97feb9bacc10
Parent:
128:9bcdf88f62b0
Release 140 of the mbed library

Ports for Upcoming Targets

3841: Add nRf52840 target https://github.com/ARMmbed/mbed-os/pull/3841
3992: Introducing UBLOX_C030 platform. https://github.com/ARMmbed/mbed-os/pull/3992

Fixes and Changes

3951: [NUCLEO_F303ZE] Correct ARDUINO pin https://github.com/ARMmbed/mbed-os/pull/3951
4021: Fixing a macro to detect when RTOS was in use for the NRF52840_DK https://github.com/ARMmbed/mbed-os/pull/4021
3979: KW24D: Add missing SPI defines and Arduino connector definitions https://github.com/ARMmbed/mbed-os/pull/3979
3990: UBLOX_C027: construct a ticker-based wait, rather than calling wait_ms(), in the https://github.com/ARMmbed/mbed-os/pull/3990
4003: Fixed OBOE in async serial tx for NRF52 target, fixes #4002 https://github.com/ARMmbed/mbed-os/pull/4003
4012: STM32: Correct I2C master error handling https://github.com/ARMmbed/mbed-os/pull/4012
4020: NUCLEO_L011K4 remove unsupported tool chain files https://github.com/ARMmbed/mbed-os/pull/4020
4065: K66F: Move bss section to m_data_2 Section https://github.com/ARMmbed/mbed-os/pull/4065
4014: Issue 3763: Reduce heap allocation in the GCC linker file https://github.com/ARMmbed/mbed-os/pull/4014
4030: [STM32L0] reduce IAR heap and stack size for small targets https://github.com/ARMmbed/mbed-os/pull/4030
4109: NUCLEO_L476RG : minor serial pin update https://github.com/ARMmbed/mbed-os/pull/4109
3982: Ticker - kl25z bugfix for handling events in the past https://github.com/ARMmbed/mbed-os/pull/3982

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 128:9bcdf88f62b0 1 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
<> 128:9bcdf88f62b0 2 *
<> 128:9bcdf88f62b0 3 * The information contained herein is property of Nordic Semiconductor ASA.
<> 128:9bcdf88f62b0 4 * Terms and conditions of usage are described in detail in NORDIC
<> 128:9bcdf88f62b0 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
<> 128:9bcdf88f62b0 6 *
<> 128:9bcdf88f62b0 7 * Licensees are granted free, non-transferable use of the information. NO
<> 128:9bcdf88f62b0 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
<> 128:9bcdf88f62b0 9 * the file.
<> 128:9bcdf88f62b0 10 *
<> 128:9bcdf88f62b0 11 */
<> 128:9bcdf88f62b0 12
<> 128:9bcdf88f62b0 13 #ifndef TWI_MASTER_H
<> 128:9bcdf88f62b0 14 #define TWI_MASTER_H
<> 128:9bcdf88f62b0 15
<> 128:9bcdf88f62b0 16
<> 128:9bcdf88f62b0 17 #ifdef __cplusplus
<> 128:9bcdf88f62b0 18 extern "C" {
<> 128:9bcdf88f62b0 19 #endif
<> 128:9bcdf88f62b0 20
<> 128:9bcdf88f62b0 21 /*lint ++flb "Enter library region" */
<> 128:9bcdf88f62b0 22
<> 128:9bcdf88f62b0 23 #include <stdbool.h>
<> 128:9bcdf88f62b0 24 #include <stdint.h>
<> 128:9bcdf88f62b0 25
<> 128:9bcdf88f62b0 26 #include "nrf51.h"
<> 128:9bcdf88f62b0 27
<> 128:9bcdf88f62b0 28 /** @file
<> 128:9bcdf88f62b0 29 * @brief Software controlled TWI Master driver.
<> 128:9bcdf88f62b0 30 *
<> 128:9bcdf88f62b0 31 *
<> 128:9bcdf88f62b0 32 * @defgroup lib_driver_twi_master Software controlled TWI Master driver
<> 128:9bcdf88f62b0 33 * @{
<> 128:9bcdf88f62b0 34 * @ingroup nrf_drivers
<> 128:9bcdf88f62b0 35 * @brief Software controlled TWI Master driver.
<> 128:9bcdf88f62b0 36 *
<> 128:9bcdf88f62b0 37 * Supported features:
<> 128:9bcdf88f62b0 38 * - Repeated start
<> 128:9bcdf88f62b0 39 * - No multi-master
<> 128:9bcdf88f62b0 40 * - Only 7-bit addressing
<> 128:9bcdf88f62b0 41 * - Supports clock stretching (with optional SMBus style slave timeout)
<> 128:9bcdf88f62b0 42 * - Tries to handle slaves stuck in the middle of transfer
<> 128:9bcdf88f62b0 43 */
<> 128:9bcdf88f62b0 44
<> 128:9bcdf88f62b0 45 #define TWI_READ_BIT (0x01) //!< If this bit is set in the address field, transfer direction is from slave to master.
<> 128:9bcdf88f62b0 46
<> 128:9bcdf88f62b0 47 #define TWI_ISSUE_STOP ((bool)true) //!< Parameter for @ref twi_master_transfer
<> 128:9bcdf88f62b0 48 #define TWI_DONT_ISSUE_STOP ((bool)false) //!< Parameter for @ref twi_master_transfer
<> 128:9bcdf88f62b0 49
<> 128:9bcdf88f62b0 50 /* These macros are needed to see if the slave is stuck and we as master send dummy clock cycles to end its wait */
<> 128:9bcdf88f62b0 51 /*lint -e717 -save "Suppress do {} while (0) for these macros" */
<> 128:9bcdf88f62b0 52 /*lint ++flb "Enter library region" */
<> 128:9bcdf88f62b0 53 #define TWI_SCL_HIGH() do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Pulls SCL line high */
<> 128:9bcdf88f62b0 54 #define TWI_SCL_LOW() do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Pulls SCL line low */
<> 128:9bcdf88f62b0 55 #define TWI_SDA_HIGH() do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Pulls SDA line high */
<> 128:9bcdf88f62b0 56 #define TWI_SDA_LOW() do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Pulls SDA line low */
<> 128:9bcdf88f62b0 57 #define TWI_SDA_INPUT() do { NRF_GPIO->DIRCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Configures SDA pin as input */
<> 128:9bcdf88f62b0 58 #define TWI_SDA_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER); } while(0) /*!< Configures SDA pin as output */
<> 128:9bcdf88f62b0 59 #define TWI_SCL_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while(0) /*!< Configures SCL pin as output */
<> 128:9bcdf88f62b0 60 /*lint -restore */
<> 128:9bcdf88f62b0 61
<> 128:9bcdf88f62b0 62 #define TWI_SDA_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_DATA_PIN_NUMBER) & 0x1UL) /*!< Reads current state of SDA */
<> 128:9bcdf88f62b0 63 #define TWI_SCL_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER) & 0x1UL) /*!< Reads current state of SCL */
<> 128:9bcdf88f62b0 64
<> 128:9bcdf88f62b0 65 #define TWI_DELAY() nrf_delay_us(4) /*!< Time to wait when pin states are changed. For fast-mode the delay can be zero and for standard-mode 4 us delay is sufficient. */
<> 128:9bcdf88f62b0 66
<> 128:9bcdf88f62b0 67
<> 128:9bcdf88f62b0 68 /**
<> 128:9bcdf88f62b0 69 * @brief Function for initializing TWI bus IO pins and checks if the bus is operational.
<> 128:9bcdf88f62b0 70 *
<> 128:9bcdf88f62b0 71 * Both pins are configured as Standard-0, No-drive-1 (open drain).
<> 128:9bcdf88f62b0 72 *
<> 128:9bcdf88f62b0 73 * @param twi The TWI interface to use - either NRF_TWI0 or NRF_TWI1
<> 128:9bcdf88f62b0 74 * @return
<> 128:9bcdf88f62b0 75 * @retval true TWI bus is clear for transfers.
<> 128:9bcdf88f62b0 76 * @retval false TWI bus is stuck.
<> 128:9bcdf88f62b0 77 */
<> 128:9bcdf88f62b0 78 bool twi_master_init_and_clear(NRF_TWI_Type* twi);
<> 128:9bcdf88f62b0 79
<> 128:9bcdf88f62b0 80 /**
<> 128:9bcdf88f62b0 81 * @brief Function for transferring data over TWI bus.
<> 128:9bcdf88f62b0 82 *
<> 128:9bcdf88f62b0 83 * If TWI master detects even one NACK from the slave or timeout occurs, STOP condition is issued
<> 128:9bcdf88f62b0 84 * and the function returns false.
<> 128:9bcdf88f62b0 85 * Bit 0 (@ref TWI_READ_BIT) in the address parameter controls transfer direction;
<> 128:9bcdf88f62b0 86 * - If 1, master reads data_length number of bytes from the slave
<> 128:9bcdf88f62b0 87 * - If 0, master writes data_length number of bytes to the slave.
<> 128:9bcdf88f62b0 88 *
<> 128:9bcdf88f62b0 89 * @note Make sure at least data_length number of bytes is allocated in data if TWI_READ_BIT is set.
<> 128:9bcdf88f62b0 90 * @note @ref TWI_ISSUE_STOP
<> 128:9bcdf88f62b0 91 *
<> 128:9bcdf88f62b0 92 * @param address Data transfer direction (LSB) / Slave address (7 MSBs).
<> 128:9bcdf88f62b0 93 * @param data Pointer to data.
<> 128:9bcdf88f62b0 94 * @param data_length Number of bytes to transfer.
<> 128:9bcdf88f62b0 95 * @param issue_stop_condition If @ref TWI_ISSUE_STOP, STOP condition is issued before exiting function. If @ref TWI_DONT_ISSUE_STOP, STOP condition is not issued before exiting function. If transfer failed for any reason, STOP condition will be issued in any case.
<> 128:9bcdf88f62b0 96 * @param twi The TWI interface to use - either NRF_TWI0 or NRF_TWI1
<> 128:9bcdf88f62b0 97 * @return
<> 128:9bcdf88f62b0 98 * @retval true Data transfer succeeded without errors.
<> 128:9bcdf88f62b0 99 * @retval false Data transfer failed.
<> 128:9bcdf88f62b0 100 */
<> 128:9bcdf88f62b0 101 bool twi_master_transfer(uint8_t address, uint8_t *data, uint8_t data_length, bool issue_stop_condition, NRF_TWI_Type* twi);
<> 128:9bcdf88f62b0 102
<> 128:9bcdf88f62b0 103 /**
<> 128:9bcdf88f62b0 104 *@}
<> 128:9bcdf88f62b0 105 **/
<> 128:9bcdf88f62b0 106
<> 128:9bcdf88f62b0 107 #ifdef __cplusplus
<> 128:9bcdf88f62b0 108 }
<> 128:9bcdf88f62b0 109 #endif
<> 128:9bcdf88f62b0 110
<> 128:9bcdf88f62b0 111 /*lint --flb "Leave library region" */
<> 128:9bcdf88f62b0 112 #endif //TWI_MASTER_H