Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
/******************************************************************************
* File Name: main.c
*
* Description: This is the source code for the XMC MCU: SPI Master Example
* for ModusToolbox. This code example shows how to transfer 3 bytes of
* data using SPI in XMC MCU. The successful transfer of bytes is
* indicated by the toggling of an LED.
*
* Related Document: See README.md
*
******************************************************************************
*
* Copyright (c) 2015-2022, Infineon Technologies AG
* All rights reserved.
*
* Boost Software License - Version 1.0 - August 17th, 2003
*
* Permission is hereby granted, free of charge, to any person or organization
* obtaining a copy of the software and accompanying documentation covered by
* this license (the "Software") to use, reproduce, display, distribute,
* execute, and transmit the Software, and to prepare derivative works of the
* Software, and to permit third-parties to whom the Software is furnished to
* do so, all subject to the following:
*
* The copyright notices in the Software and this entire statement, including
* the above license grant, this restriction and the following disclaimer,
* must be included in all copies of the Software, in whole or in part, and
* all derivative works of the Software, unless such copies or derivative
* works are solely in the form of machine-executable object code generated by
* a source language processor.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#include "cybsp.h"
#include "cy_utils.h"
#include <stdio.h>
#include "cy_retarget_io.h"
/*******************************************************************************
* Defines
*******************************************************************************/
/* Declarations for LED toggle and SPI transmission timing */
#define TICKS_PER_SECOND (1000u)
#define TICKS_WAIT (1000u)
/* Define macro to enable/disable printing of debug messages */
#define ENABLE_XMC_DEBUG_PRINT (0)
/* Define macro to check if loop is entered once */
#if ENABLE_XMC_DEBUG_PRINT
static bool ENTER_LOOP = false;
static uint8_t LOOP_NUM = 0;
#endif
/* Declaration of array to store the message to be transmitted */
const uint8_t data[3] = {0x84, 0x0F, 0x84};
/*******************************************************************************
* Function Name: SysTick_Handler
********************************************************************************
* Summary:
* This is the interrupt handler function for the SysTick timer interrupt.
* It counts the time elapsed in milliseconds since the timer started.
*
* Parameters:
* void
*
* Return:
* void
*
*******************************************************************************/
void SysTick_Handler(void)
{
/* Variables Initialization */
uint8_t i = 0;
static uint32_t ticks = 0;
ticks++;
if (ticks == TICKS_WAIT)
{
/* Enable the selected slave Select line 0 */
XMC_SPI_CH_EnableSlaveSelect(SPI0_HW, XMC_SPI_CH_SLAVE_SELECT_0);
/* Sending 3 messages from data array */
while(i < 3)
{
XMC_SPI_CH_Transmit(SPI0_HW, data[i++], XMC_SPI_CH_MODE_STANDARD);
while((XMC_SPI_CH_GetStatusFlag(SPI0_HW) & XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION) == 0U);
XMC_SPI_CH_ClearStatusFlag(SPI0_HW, XMC_SPI_CH_STATUS_FLAG_TRANSMIT_SHIFT_INDICATION);
}
/* Transfer completed successfully. Toggle the LED */
XMC_GPIO_ToggleOutput(CYBSP_USER_LED1_PORT, CYBSP_USER_LED1_PIN);
/* Disable Slave Select line */
XMC_SPI_CH_DisableSlaveSelect( SPI0_HW );
#if ENABLE_XMC_DEBUG_PRINT
ENTER_LOOP = true;
#endif
ticks = 0;
}
}
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
* This is the main function. It initializes the SPI interface and configures
* SPI block for transmitting data.
*
* Parameters:
* void
*
* Return:
* int
*
*******************************************************************************/
int main(void)
{
cy_rslt_t result;
/* Initialize the device and board peripherals */
result = cybsp_init();
if (result != CY_RSLT_SUCCESS)
{
CY_ASSERT(0);
}
cy_retarget_io_init(CYBSP_DEBUG_UART_HW);
#if ENABLE_XMC_DEBUG_PRINT
printf("Initialization done\r\n");
#endif
/* Start the SPI Channel */
XMC_SPI_CH_Start( SPI0_HW );
/* System timer configuration */
SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);
while(1)
{
#if ENABLE_XMC_DEBUG_PRINT
if(ENTER_LOOP && LOOP_NUM == 0)
{
printf("Data sent\r\n");
LOOP_NUM++;
}
#endif
}
}
/* [] END OF FILE */