Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15404

Spi interrupt issue

$
0
0

HI all ,
i am using RPI4 and two Arduino nano 33 iot using spi connection
i shared miso mosi sck but while i am running heartbeat check function on 1 Arduino but i am getting clock interrupt on second Arduino even though chip select connections is not there
pinMode(slaveAPin, INPUT_PULLUP);
//attachInterrupt(digitalPinToInterrupt(slaveAPin), SERCOM1_Handler, FALLING);
spiSlave_init();
this function is running continuedly but it is comment how it is running
PORT->Group[PORTA].PINCFG[16].bit.PMUXEN = 0x1; // Enable Peripheral Multiplexing for SERCOM1 SPI PA18 Arduino PIN10
PORT->Group[PORTA].PMUX[8].bit.PMUXE = 0x2; // SERCOM 1 is selected for peripherial use of this pad
PORT->Group[PORTA].PINCFG[17].bit.PMUXEN = 0x1; // Enable Peripheral Multiplexing for SERCOM1 SPI PA18 Arduino PIN10
PORT->Group[PORTA].PMUX[8].bit.PMUXO = 0x2; // SERCOM 1 is selected for peripherial use of this pad
PORT->Group[PORTA].PINCFG[21].bit.PMUXEN = 0x1; // Enable Peripheral Multiplexing for SERCOM1 SPI PA18 Arduino PIN10
PORT->Group[PORTA].PMUX[9].bit.PMUXE = 0x2; // SERCOM 1 is selected for peripherial use of this pad
PORT->Group[PORTA].PINCFG[19].bit.PMUXEN = 0x1; // Enable Peripheral Multiplexing for SERCOM1 SPI PA18 Arduino PIN10
PORT->Group[PORTA].PMUX[9].bit.PMUXO = 0x2; // SERCOM 1 is selected for peripherial use of this pad

// Disable SPI 1
SERCOM1->SPI.CTRLA.bit.ENABLE = 0;
while (SERCOM1->SPI.SYNCBUSY.bit.ENABLE)
;

// Reset SPI 1
SERCOM1->SPI.CTRLA.bit.SWRST = 1;
while (SERCOM1->SPI.CTRLA.bit.SWRST || SERCOM1->SPI.SYNCBUSY.bit.SWRST)
;

// Setting up NVIC
NVIC_EnableIRQ(SERCOM1_IRQn);
NVIC_SetPriority(SERCOM1_IRQn, 2);

// Setting Generic Clock Controller!!!!
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID(GCM_SERCOM1_CORE) | // Generic Clock 0
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is the source
GCLK_CLKCTRL_CLKEN; // Enable Generic Clock Generator

while (GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY)
; // Wait for synchronisation

// Set up SPI Control A Register
SERCOM1->SPI.CTRLA.bit.DORD = 0; // MSB first
SERCOM1->SPI.CTRLA.bit.CPOL = 0; // SCK is low when idle, leading edge is rising edge
SERCOM1->SPI.CTRLA.bit.CPHA = 0; // data sampled on leading sck edge and changed on a trailing sck edge
SERCOM1->SPI.CTRLA.bit.FORM = 0x0; // Frame format = SPI
SERCOM1->SPI.CTRLA.bit.DIPO = 0x0; // DATA PAD0 MOSI is used as input (slave mode)
SERCOM1->SPI.CTRLA.bit.DOPO = 0x2; // DATA PAD3 MISO is used as output
SERCOM1->SPI.CTRLA.bit.MODE = 0x2; // SPI in Slave mode
SERCOM1->SPI.CTRLA.bit.IBON = 0x1; // Buffer Overflow notification
SERCOM1->SPI.CTRLA.bit.RUNSTDBY = 1; // wake on receiver complete

// Set up SPI control B register
// SERCOM1->SPI.CTRLB.bit.RXEN = 0x1; //Enable Receiver
SERCOM1->SPI.CTRLB.bit.SSDE = 0x1; // Slave Selecte Detection Enabled
SERCOM1->SPI.CTRLB.bit.CHSIZE = 0; // character size 8 Bit
SERCOM1->SPI.CTRLB.bit.PLOADEN = 0x1; // Enable Preload Data Register
while (SERCOM1->SPI.SYNCBUSY.bit.CTRLB)
;

// Set up SPI interrupts
SERCOM1->SPI.INTENSET.bit.SSL = 0x1; // Enable Slave Select low interrupt
SERCOM1->SPI.INTENSET.bit.RXC = 0x1; // Receive complete interrupt
SERCOM1->SPI.INTENSET.bit.TXC = 0x0; // Receive complete interrupt
SERCOM1->SPI.INTENSET.bit.ERROR = 0x0; // Receive complete interrupt
SERCOM1->SPI.INTENSET.bit.DRE = 0x0; // Data Register Empty interrupt

// init SPI CLK
// SERCOM1->SPI.BAUD.reg = SERCOM_FREQ_REF / (2*4000000u)-1;
// Enable SPI
SERCOM1->SPI.CTRLA.bit.ENABLE = 1;
while (SERCOM1->SPI.SYNCBUSY.bit.ENABLE)
;
SERCOM1->SPI.CTRLB.bit.RXEN = 0x1; // Enable Receiver, this is done here due to errate issue
while (SERCOM1->SPI.SYNCBUSY.bit.CTRLB)
; // wait until receiver is enabled
}
what i need to change here please help me if any one have any idea about this ?

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 15404

Trending Articles