4.2.2 Configuring Bus (SPI) Wrapper
Perform the following changes in the bus (SPI) wrapper file.
- Modify the following set of functions
based on the PIC24 MCU bus (SPI) in the
nm_bsp_PIC24.c
file.nm_bus_init
– This function is used for the SPI bus initialize functionality.nm_bus_ioctl
– This function provides the sending/receiving of data using the SPI functionality.nm_bus_deinit
– This function is used for the SPI bus de-initialize functionality.nm_bus_reinit
– This function is used for the SPI bus re-initialize functionality.The following is the modifiednm_bsp_PIC24.c
file source code.#include "../mcc_generated_files/mcc.h" #include "bsp/include/nm_bsp.h" #include "common/include/nm_common.h" #include "conf_winc.h" #include "../main.h" tpfNmBspIsr gpfIsr; /* * @fn init_chip_pins * @brief Initialize reset, chip enable and wake pin */ static void init_chip_pins(void) { // Initialization HANDLED in MCC // Set initial values for the GPIO signals WINC_ASSERT_RESET(); WINC_RELEASE_CHIP_EN(); WINC_WAKE_LOW(); } /* * @fn nm_bsp_init * @brief Initialize BSP * @return 0 in case of success and -1 in case of failure */ sint8 nm_bsp_init(void) { gpfIsr = NULL; /* Initialize chip IOs. */ init_chip_pins(); /* Perform chip reset. */ nm_bsp_reset(); return M2M_SUCCESS; } /** * @fn nm_bsp_deinit * @brief De-iInitialize BSP * @return 0 in case of success and -1 in case of failure */ sint8 nm_bsp_deinit(void) { // HANDLED BY MCC return M2M_SUCCESS; } /** * @fn nm_bsp_reset * @brief Reset NMC1500 SoC by setting CHIP_EN and RESET_N signals low, CHIP_EN high then RESET_N high */ void nm_bsp_reset(void) { WINC_RELEASE_CHIP_EN(); WINC_ASSERT_RESET(); nm_bsp_sleep(100); WINC_ASSERT_CHIP_EN(); nm_bsp_sleep(10); WINC_RELEASE_RESET(); nm_bsp_sleep(10); } /* * @fn nm_bsp_sleep * @brief Sleep in units of mSec * @param[IN] u32TimeMsec * Time in milliseconds */ void nm_bsp_sleep(uint32 u32TimeMsec) { while (u32TimeMsec--) { delay_ms(1); } } /* * @fn nm_bsp_register_isr * @brief Register interrupt service routine * @param[IN] pfIsr * Pointer to ISR handler */ void nm_bsp_register_isr(tpfNmBspIsr pfIsr) { gpfIsr = pfIsr; } /* * @fn nm_bsp_interrupt_ctrl * @brief Enable/Disable interrupts * @param[IN] u8Enable * '0' disable interrupts. '1' enable interrupts */ void nm_bsp_interrupt_ctrl(uint8 u8Enable) { if (u8Enable) { WINC_INT_ENABLE; } else { WINC_INT_DISABLE; } }
- Modify the
nm_bsp_PIC24.h
file to the following:#ifndef _NM_BSP_PIC24_H_ #define _NM_BSP_PIC24_H_ #include "conf_winc.h" #define NM_EDGE_INTERRUPT (1) #define NM_DEBUG CONF_WINC_DEBUG #define NM_BSP_PRINTF CONF_WINC_PRINTF #endif /* _NM_BSP_PIC24_H_ */
- Right click on the project Source Files, then choose Add Existing Items from Folders... to add the ATWINC1500 source code to the project.
- Click Add Folder, then provide the path “wifi_PIC24F_WINC15x0\wifi_PIC24F_WINC15x0.X\winc1500” and select all of the files types.
- Create the configuration files.
- Right click the project Header Files, then create the config directory.
- In the “config” directory,
create the
conf_winc.h
file, then add the following code:#ifndef CONF_WINC_H_INCLUDED #define CONF_WINC_H_INCLUDED #ifdef __cplusplus extern "C" { #endif #include "../mcc_generated_files/mcc.h" /* --------------------------------- ---------- SPI settings --------- --------------------------------- */ #define CONF_WINC_USE_SPI (1) /** SPI pin and instance settings. */ #define WINC_SPI_INTERFACE SPI2 // Define functions used by the WINC1500 driver to interface with // the SPI bus #define WINC_SPI_TRANSCEIVE SPI2_Exchange8bit #define WINC_SPI_SELECT_SLAVE SPI_SS_SetLow() #define WINC_SPI_UNSELECT_SLAVE SPI_SS_SetHigh() /** WINC1500 External Interrupt Enable/Disable functions */ #define WINC_INT_ENABLE EX_INT3_InterruptEnable() #define WINC_INT_DISABLE EX_INT3_InterruptDisable() /** GPIO control definitions */ #define WINC_ASSERT_RESET() WINC_RESET_SetLow() #define WINC_RELEASE_RESET() WINC_RESET_SetHigh() #define WINC_ASSERT_CHIP_EN() WINC_CHIP_EN_SetHigh() #define WINC_RELEASE_CHIP_EN() WINC_CHIP_EN_SetLow() #define WINC_WAKE_HIGH() WINC_WAKE_SetHigh() #define WINC_WAKE_LOW() WINC_WAKE_SetLow() #define CONF_WINC_DEBUG (1) #define CONF_WINC_PRINTF printf #ifdef __cplusplus } #endif #endif /* CONF_WINC_H_INCLUDED */
- Right click on the project, then choose Properties. Add __PIC24__ in "Define common macros" field.
- Add the folder path of winc1500 and config in the "C include dirs" field.