I am building a digital modulator for a hand-held radio. When the transmit button is pushed, it triggers an interrupt on GPIOC bit 18. I have tested it with both of the edge triggers and also high-level triggers and it works fine. When I switch to low-level triggers it crashes as soon as it executes
NVIC_EnableIRQ(PORTC_IRQn);
The voltage on the pin is 2.1V whne the button is not pushed, so it is definitely recognising a HI as it interrupts fine when the button is not pressed and I set it to HI level trigger with the following instruction:
PORTC_PCR18 = 0xC0100;
(Yes, the PTT switch works backwards perfectly. So it must be recognising a true LO when the switch is pushed.
But why does it crash when I use:
PORTC_PCR18 = 0x80100; ???
*/
#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MK64F12.h"
#include "fsl_debug_console.h"
#include "GUMP.h"
#include "frere.h"
#include "stdint.h"
//#include "inttypes.h"
#include "stdio.h"
#include "string.h"
#include "fsl_dspi.h" // not found in mcuexpresso, taking chance of copying from KDS 2022 02 10 NWJ
#include "board.h"
#include "pin_mux.h"
#include "clock_config.h"
#define DSPI_MASTER_BASEADDR SPI1
#define DSPI_MASTER_CLK_SRC DSPI1_CLK_SRC
#define DSPI_MASTER_CLK_FREQ CLOCK_GetFreq(DSPI1_CLK_SRC)
#define DSPI_MASTER_IRQ SPI1_IRQn
#define DSPI_MASTER_PCS kDSPI_Pcs0
#define DSPI_MASTER_IRQHandler SPI1_IRQHandler
#define DSPI_SLAVE_BASEADDR SPI1
#define DSPI_SLAVE_IRQ SPI1_IRQn
#define DSPI_SLAVE_IRQHandler SPI1_IRQHandler
//#define TRANSFER_SIZE 256U // Transfer dataSize
#define TRANSFER_SIZE 10 // Transfer dataSize
#define TRANSFER_BAUDRATE 500000U // Transfer baudrate - 500k
#define SPI_PUSHR_PCS0_ON 0x10000
#define SPI_PUSHR_PCS1_ON 0x20000
#define SPI_PUSHR_PCS2_ON 0x40000
#define SPI_PUSHR_PCS3_ON 0x80000
#define SPI_PUSHR_PCS4_ON 0x100000
#define SPI_PUSHR_PCS5_ON 0x200000
#define SPI_CTAR_FMSZ_8BIT 0x38000000
#define SPI_CTAR_FMSZ_16BIT 0x78000000
#define INIT 1 // arguments for the lcd routine
#define UPDATE 2 //
const char line1[]="Frere Radio ";
const char line2[]="System V0.1 ";
const char line1a[]="Copyright(c)2022";
const char line2a[]="Nigel W. Johnson";
const char line1b[]=" ";
const char line2b[]=" ";
unsigned char cmd = 0x01;
unsigned char receiveBuffer[3];
uint8_t masterRxData[TRANSFER_SIZE] = {0U};
uint8_t masterTxData[TRANSFER_SIZE] = {0U};
uint8_t slaveRxData[TRANSFER_SIZE] = {0U};
uint8_t slaveTxData[TRANSFER_SIZE] = {0U};
volatile uint32_t slaveTxCount;
volatile uint32_t slaveRxCount;
volatile uint32_t masterTxCount;
volatile uint32_t masterRxCount;
volatile uint32_t masterCommand;
uint32_t masterFifoSize;
dspi_master_handle_t g_m_handle;
dspi_slave_handle_t g_s_handle;
volatile bool isTransferCompleted = false;
//#pragma section m_data
char RAM_line1[16];
char RAM_line2[16];
unsigned char a[16];
char *pointer;
char temp;
int char_Pos; // where we are in LCD line
int dest;
int i;
unsigned int TxHex,RxHex;
unsigned char TxHex1,TxHex2,TxHex3,TxHex4; // storage for raw data in hex and unpacked digits
unsigned char RxHex1,RxHex2,RxHex3,RxHex4; // storage for raw data in hex and unpacked digits
unsigned short ADC_read16b(void);
unsigned short bADCData;
void send_spi(void);
void receive_spi(void);
/*
* @brief Application entry point.
*/
int main(void)
{
SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; /*Enable Port C Clock Gate Control*/
PORTC_PCR18 = 0x80100; /*PORTC_PC18: ISF=0,IRQC=A (Low-level trigger ,MUX=1 */
GPIOC_PDDR |= (0 << 18); /*Setting the bit 6 of the port C as Input*/
PORTC_ISFR = PORT_ISFR_ISF(0x40); /* Clear interrupt status flag */
NVIC_EnableIRQ(PORTC_IRQn); /*Enable the PORTC interrupt*/