Skip to content

Latest commit

 

History

History
204 lines (122 loc) · 14.7 KB

README.md

File metadata and controls

204 lines (122 loc) · 14.7 KB

XMC™ MCU: SPI master

This code example demonstrates the transfer of three bytes of data using the SPI master in XMC™ MCU. The successful completion of transfer is indicated by the toggling of an LED on the board.

Requirements

Supported toolchains (make variable 'TOOLCHAIN')

  • GNU Arm® Embedded Compiler v10.3.1 (GCC_ARM) - Default value of TOOLCHAIN

Supported kits (make variable 'TARGET')

Hardware setup

This example uses the board's default configuration. See the kit user guide to ensure that the board is configured correctly.

Use jumper wires to establish a connection between the master and the slave. The pin assignments for the master and slave devices for the supported kits are listed in Table 1.

Table 1. Pin connections to the SPI slave kit

Development kit MOSI MISO SCLK CS Ground
KIT_XMC11_BOOT_001 1[0] 2[0] 0[8] 0[9] GND
KIT_XMC12_BOOT_001 1[0] 2[0] 0[8] 0[9] GND
KIT_XMC13_BOOT_001 1[0] 2[0] 0[8] 0[9] GND
KIT_XMC14_BOOT_001 1[0] 2[0] 0[8] 0[9] GND
KIT_XMC_PLT2GO_XMC4200 0[5] 0[4] 0[11] 0[6] GND
KIT_XMC_PLT2GO_XMC4400 0[5] 0[4] 0[11] 0[6] GND
KIT_XMC45_RELAX_V1 2[14] 2[15] 0[11] 0[6] GND
KIT_XMC47_RELAX_V1 0[5] 0[4] 0[11] 0[6] GND
KIT_XMC43_RELAX_ECAT_V1 0[5] 0[4] 0[11] 0[6] GND
KIT_XMC48_RELAX_ECAT_V1 0[5] 0[4] 0[11] 0[6] GND

Connect the master's MOSI to the slave's MOSI, MISO to MISO, SCLK to SCLK, and CS to CS.

Software setup

This example requires no additional software or tools.

Using the code example

Create the project and open it using one of the following:

In Eclipse IDE for ModusToolbox™ software
  1. Click the New Application link in the Quick Panel (or, use File > New > ModusToolbox Application). This launches the Project Creator tool.

  2. Pick a kit supported by the code example from the list shown in the Project Creator - Choose Board Support Package (BSP) dialog.

    When you select a supported kit, the example is reconfigured automatically to work with the kit. To work with a different supported kit later, use the Library Manager to choose the BSP for the supported kit. You can use the Library Manager to select or update the BSP and firmware libraries used in this application. To access the Library Manager, click the link from the Quick Panel.

    You can also just start the application creation process again and select a different kit.

    If you want to use the application for a kit not listed here, you may need to update the source files. If the kit does not have the required resources, the application may not work.

  3. In the Project Creator - Select Application dialog, choose the example by enabling the checkbox.

  4. (Optional) Change the suggested New Application Name.

  5. The Application(s) Root Path defaults to the Eclipse workspace which is usually the desired location for the application. If you want to store the application in a different location, you can change the Application(s) Root Path value. Applications that share libraries should be in the same root path.

  6. Click Create to complete the application creation process.

For more details, see the Eclipse IDE for ModusToolbox™ software user guide (locally available at {ModusToolbox™ software install directory}/ide_{version}/docs/mt_ide_user_guide.pdf).

In command-line interface (CLI)

ModusToolbox™ software provides the Project Creator as both a GUI tool and the command line tool, "project-creator-cli". The CLI tool can be used to create applications from a CLI terminal or from within batch files or shell scripts. This tool is available in the {ModusToolbox™ software install directory}/tools_{version}/project-creator/ directory.

Use a CLI terminal to invoke the "project-creator-cli" tool. On Windows, use the command line "modus-shell" program provided in the ModusToolbox™ software installation instead of a standard Windows command-line application. This shell provides access to all ModusToolbox™ software tools. You can access it by typing modus-shell in the search box in the Windows menu. In Linux and macOS, you can use any terminal application.

This tool has the following arguments:

Argument Description Required/optional
--board-id Defined in the <id> field of the BSP manifest Required
--app-id Defined in the <id> field of the CE manifest Required
--target-dir Specify the directory in which the application is to be created if you prefer not to use the default current working directory Optional
--user-app-name Specify the name of the application if you prefer to have a name other than the example's default name Optional

The following example will clone the "SPI MASTER" application with the desired name "MySPIMASTER" configured for the KIT_XMC14_BOOT_001 BSP into the specified working directory, C:/mtb_projects:

project-creator-cli --board-id KIT_XMC14_BOOT_001 --app-id mtb-example-xmc-spi-master --user-app-name MySPIMASTER --target-dir "C:/mtb_projects"

Note: The project-creator-cli tool uses the git clone and make getlibs commands to fetch the repository and import the required libraries. For details, see the "Project creator tools" section of the ModusToolbox™ software user guide (locally available at {ModusToolbox™ software install directory}/docs_{version}/mtb_user_guide.pdf).

In third-party IDEs

Note: Only VS Code is supported.

  1. Follow the instructions from the In command-line interface (CLI) section to create the application, and import the libraries using the make getlibs command.

  2. Export the application to a supported IDE using the make <ide> command.

    For a list of supported IDEs and more details, see the "Exporting to IDEs" section of the ModusToolbox™ software user guide (locally available at {ModusToolbox™ software install directory}/docs_{version}/mtb_user_guide.pdf).

  3. Follow the instructions displayed in the terminal to create or import the application as an IDE project.

Operation

  1. Connect the board to your PC using a micro-USB cable through the debug USB connector.

  2. Program the board using Eclipse IDE for ModusToolbox™ software:

    1. Select the application project in the Project Explorer.

    2. Enter the data to be sent in the data array given in the main.c file.

    3. In the Quick Panel, scroll down, and click <Application Name> Program (JLink).

  3. Check whether the LED toggles, which confirm the completion of the transfer of three bytes.

    This can also be checked with the help of a logic analyser or an oscilloscope by probing out the MOSI pin.

    See the Hardware setup section for the pin connections of the supported kits.

Debugging

You can debug the example to step through the code. In the IDE, use the <Application Name> Debug (JLink) configuration in the Quick Panel. For more details, see the "Program and debug" section in the Eclipse IDE for ModusToolbox™ user guide.

Design and implementation

In this code example, the SPI block of the XMC™ MCU is configured as the SPI master to send three bytes of data to the SPI slave. After the initialization of the SPI peripheral, the input stage for synchronous serial communication (SSC/SPI) and the SPI channel are set for communication.

The SPI master enables the slave select line to start the transfer of three bytes of data. The status flag for the SPI channel is continuously set to consider the events into account that take place during communication. Therefore, during the communication, the events occurred must be cleared to detect their next occurrence. The successful completion of transfer is indicated by toggling of an LED on the board.

Related resources

Resources Links
Code examples Using ModusToolbox™ software on GitHub
Device documentation XMC1000 family datasheets
XMC1000 family technical reference manuals
XMC4000 family datasheets
XMC4000 family technical reference manuals
Development kits XMC™ eval boards
Libraries on GitHub mtb-xmclib-cat3 – XMC™ peripheral driver library (XMCLib)
Tools Eclipse IDE for ModusToolbox™ software – ModusToolbox™ software is a collection of easy-to-use software and tools enabling rapid development with Infineon MCUs, covering applications from embedded sense and control to wireless and cloud-connected systems using AIROC™ Wi-Fi and Bluetooth® connectivity devices.

Other resources

Infineon provides a wealth of data at www.infineon.com to help you select the right device, and quickly and effectively integrate it into your design.

For XMC™ MCU devices, see 32-bit XMC™ industrial microcontroller based on Arm® Cortex®-M.

Document history

Document title: CE232739 - XMC™ MCU: SPI master

Version Description of change
1.0.0 New code example
1.1.0 Added support for new kits
2.0.0 Added support for SPI personality; Updated to support ModusToolbox software v3.0; CE will not be backwards compatible with previous versions of ModusToolbox™ software
2.0.1 Updated README

All other trademarks or registered trademarks referenced herein are the property of their respective owners.

© 2022 Infineon Technologies AG

All Rights Reserved.

Legal disclaimer

The information given in this document shall in no event be regarded as a guarantee of conditions or characteristics. With respect to any examples or hints given herein, any typical values stated herein and/or any information regarding the application of the device, Infineon Technologies hereby disclaims any and all warranties and liabilities of any kind, including without limitation, warranties of non-infringement of intellectual property rights of any third party.

Information

For further information on technology, delivery terms and conditions and prices, please contact the nearest Infineon Technologies Office (www.infineon.com).

Warnings

Due to technical requirements, components may contain dangerous substances. For information on the types in question, please contact the nearest Infineon Technologies Office.

Infineon Technologies components may be used in life-support devices or systems only with the express written approval of Infineon Technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system or to affect the safety or effectiveness of that device or system. Life support devices or systems are intended to be implanted in the human body or to support and/or maintain and sustain and/or protect human life. If they fail, it is reasonable to assume that the health of the user or other persons may be endangered.