Hello everyone.
Hello this is my SPI code:
spi.h:
// --------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////////////////
void SPI_Init(void);
void SPI_SetSCK(unsigned long int BusClock_freq, unsigned long int SCLK_freq);
void SPI_PutChar1(unsigned char chr);
void SPI_PutBuffer1(unsigned int dim, unsigned char *chr);
void SPI_GetChar1(unsigned char *chr);
void SPI_GetBuffer1(unsigned int dim, unsigned char *chr);
spi.c:
#include "derivative.h"
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
/////////#define SPI2S_SPTEF_MASK 0b00100000 // bit5 SPTEF definidas en MCF51EM256
/////////#define SPI2S_SPRF_MASK 0b10000000 // bit7 SPRF
/////////////////////////////////////////////////////////////////////////////////////////
// SPI_Init
// --------------------------------------------------------------------------------------
// /////////////////////////////////////////////////////////////////////////////////////////
void SPI_Init(void)
{
unsigned char status;
status = SPI2S;
status = SPI2D;
SPI2C1 = 0x00; //.
SPI2C2 = 0x00;
// SPIE=1; SPE=1; SPTIE=1; MSTR=1; CPOL=1; CPHA=0; SSOE=1; LSBFE=0
SPI2C1 = 0xFA;
// SPMIE=0; SPIMODE=1; bit5=0; MODFEN=1; BIDIROE=0; bit2=0; SPISWAI=1; SPC0=0
SPI2C2 = 0x52;
//
SPI2S = 0x00; // SPRF; SPMF; SPTEF; MODF; 0; 0; 0; 0
status = SPI2D;
}
/////////////////////////////////////////////////////////////////////////////////////////
// SPI_SetSCK
// --------------------------------------------------------------------------------------
//
/////////////////////////////////////////////////////////////////////////////////////////
void SPI_SetSCK(unsigned long int BusClock_freq, unsigned long int SCLK_freq)
{
unsigned long int BRdiv;
// bit7=0; SPPR2=0; SPPR1=0; SPPR0=1; SPR3=0; SPR2=0; SPR1=0; SPR0=1
// Prescale divisor=2; Rate divisor=4.
SPI2BR=0x11;
BRdiv = BusClock_freq / SCLK_freq;
}
/////////////////////////////////////////////////////////////////////////////////////////
// SPI_PutChar
// --------------------------------------------------------------------------------------
//
/////////////////////////////////////////////////////////////////////////////////////////
void SPI_PutChar1(unsigned char chr)
{
unsigned char data;
// while (!(SPI2S & SPI2S_SPTEF_MASK))
;
// SPI2D = chr;
while (!(SPI2S & SPI2S_SPRF_MASK))
;
//
data = SPI2D;
}
/////////////////////////////////////////////////////////////////////////////////////////
// SPI_PutBuffer
// --------------------------------------------------------------------------------------
//
/////////////////////////////////////////////////////////////////////////////////////////
void SPI_PutBuffer1(unsigned int dim, unsigned char *chr)
{
unsigned int i;
for (i = 0; i<dim; i++)
{
SPI_PutChar(*chr++);
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// SPI_GetChar
// --------------------------------------------------------------------------------------
// /////////////////////////////////////////////////////////////////////////////////////////
void SPI_GetChar1(unsigned char *chr)
{
while(!(SPI2S & SPI2S_SPTEF_MASK))
;
while(!(SPI2S & SPI2S_SPRF_MASK))
;
*chr = SPI2D; //
}
/////////////////////////////////////////////////////////////////////////////////////////
// SPI_GetBuffer
// --------------------------------------------------------------------------------------
//
/////////////////////////////////////////////////////////////////////////////////////////
void SPI_GetBuffer1(unsigned int dim,unsigned char *chr)
{
unsigned int i;
for (i = 0; i<dim; i++)
SPI_GetChar(chr++);
}
With this code I want to communicate MCF51EM256 and ADE7753 device, but I don´t know how implement the interface in RS-232 between MCF51EM256 and PC.
I wait your reply, thanks so much.
Yours sincerely.
Fermin.
I must use UART-SPI of MCF51EM256?
I hope your replies,
thanks
Best Regards