AnsweredAssumed Answered

SPI communication (KDS 3.0 without PE and KSDK)

Question asked by Matheus Kotaki on Oct 25, 2017
Latest reply on Oct 31, 2017 by Mark Butcher

Hello,

 

I am using the FRDM-K64F development platform, and I have to communicate it with the board ADS1298 ECG FE using the SPI communication. Running the algorithm below, the FRDM-K64F only completes two transfers, but if I run it step by step it completes all the tranfers and in the last transfer the FRDM-K64F should receive 0x06, and it receives the right data; but, the variable 'rx' remains zero.

 


#include "MK64F12.h"

 

void config_ports(void){

//Habilitar os clocks dos ports
SIM_SCGC5 |= (1<<12) | (1<<11);
SIM_SCGC6 |= (1<<12);

//config. SPI0_PCS0
PORTD_PCR0 |= (1<<9) | (1<<6) | (1<<1);
PORTD_PCR0 &= ~(1<<5) & ~(1<<4) & ~(1<<2) & ~(1) ;

//config. SPI0_SCK
PORTD_PCR1 |= (1<<9) | (1<<6) | (1<<1);
PORTD_PCR1 &= ~(1<<5) & ~(1<<4) & ~(1<<2) & ~(1);

//config. SPI0_SOUT
PORTD_PCR2 |= (1<<9) | (1<<6) | (1<<1);
PORTD_PCR2 &= ~(1<<5) & ~(1<<4) & ~(1<<2) & ~(1);

//config. SPI0_SIN
PORTD_PCR3 |= (1<<9) | (1<<1);
PORTD_PCR3 &= ~(1<<5) & ~(1<<4) & ~(1);
}

void config_SPI0(void){
//Module Config.
SPI0_MCR |= (1<<31) | (0<<30) | (1<<16) | (1<<11) | (1<<10);
SPI0_MCR &= ~(1) & ~(1<<14);
SPI0_SR |= (1<<28);
//Clock and Transfer Attributes
SPI0_CTAR0 |= (1<<25) | (1<<22) | (1<<17) | (1<<16) | (1<<10) | (1<<9) | (1<<6) | (1<<5) | (1<<2) | (1) ;
SPI0_CTAR0 &= ~(1<<30);
}

 


void transmit_SPI0(uint8_t tx){
SPI0_MCR |= (1<<11);
SPI0_PUSHR |= (1<<16) |(tx);//CTAR0
}

void transmit2_SPI0(uint8_t tx){
SPI0_MCR |= (1<<11);
SPI0_PUSHR |= (1<<31) | (1<<16) |(tx);
}

void waitSPI(void){
while(SPI0_SR>>31==0){}
}

uint32_t read_REG(uint8_t reg){
uint32_t temp;
reg |= (1<<5);
SPI0_MCR |= (1<<10);
transmit2_SPI0(reg);
waitSPI();
transmit2_SPI0(0x00);
waitSPI();
SPI0_MCR |= (1<<11);
SPI0_PUSHR |= (1<<27) | (1<<16) |(0x00);
waitSPI();
temp = (uint32_t)SPI0_POPR;
return temp;
}

void delay_reset(void){
uint32_t i=610;
while(i>0){
i--;
}


}

int main(void)
{
uint8_t wakeup = 0x02;
uint8_t reset = 0x06;
uint8_t sdatac = 0x11;
uint8_t stop = 0x0A;
uint32_t rx=0;
config_ports();
config_SPI0();


transmit_SPI0(reset);
delay_reset();
transmit_SPI0(wakeup);
transmit_SPI0(sdatac);
transmit_SPI0(stop);
rx = read_REG(0x01);


while(1){


}
/* Never leave main */
return 0;
}

Outcomes