Confidential & Proprietary Information
To initialize the HAL, call the function “i2c_initialize_hal(NULL);”
This will initialize the pins on the I
2
C port to those provided on the module.
Advanced users can tweak the settings, or assign other module GPIO pins (after removing those pins from the GPIO list) by
calling the function above with a pointer to a structure like the following (default values shown):
static i2c_config_t m_i2c_hal_default_config =
{
.u32_scl_pin = I2C_1_SCL_PIN,
.u32_sda_pin = I2C_1_SDA_PIN,
.frequency = I2C_1_FREQUENCY,
.u8_interrupt_priority = APP_IRQ_PRIORITY_LOW,
};
Assigning pins for peripheral interface.
To assign pins for use by peripheral devices (SPI ports, I
2
C ports, UARTS, etc), they should first be removed from the GPIO
list in the file: UAPI_GPIO_list.c
Then, the pins you intend to assign should be reserved in the GPIO library with a call to the function:
int32_t g_library_set_pin_pinmap_by_pin_number(uint32_t u32_pin_no);
This function takes the Nordic pin number as an argument and will return an error code if the pin is already reserved. The
function is found in GSTAR_Library_gpio.c and its definition can be included in your source file by including
GSTAR_Library_gpio.h
To check if a pin is already reserved, use:
int32_t g_library_get_pin_pinmap_by_pin_number(uint32_t u32_pin_no);
Example of re-assigning an I
2
C peripheral
•
Remove the pins you intend to use for the I
2
C peripheral from the GPIO list in UAPI_GPIO_list.c (as described in
the previous section).
•
You could, optionally, add GPIO definitions to the “default” I
2
C pins that you are re-assigning.
o
I2C_CLK = 43 (1.11)
o
I2C_SDA = 45 (1.13)
•
Use the function “int32_t g_library_set_pin_pinmap_by_pin_number(uint32_t u32_pin_no);” to reserve the pins
you intend to move the I
2
C peripheral to.
•
Create a structure as shown below, with the pin assignments you intend to use.
•
Then call:
o
bool ret_val = i2c_initialize_hal(&m_i2c_hal_my_config)
i2c_config_t m_i2c_hal_my_config =
{
.u32_scl_pin = I2C_1_SCL_PIN,
.u32_sda_pin = I2C_1_SDA_PIN,
.frequency = I2C_1_FREQUENCY,
.u8_interrupt_priority = APP_IRQ_PRIORITY_LOW,
};
Setting up a SPI master peripheral
The Nordic nRF52840 can support up to 4 SPI master interfaces. At the Nordic SDK level, the SPI Master interfaces are
identified via “instances” 1 – 4. The ST150M uses instance 1 to communicate with its on board GPS receiver. External
devices cannot be added to this SPI port since its signals are dedicated to the GPS and are not brought out to external
pins. This leaves instances 2 – 4 available for other uses via custom code.