Grzegorz Lysko

Slow SPI

Discussion created by Grzegorz Lysko on Nov 26, 2006
Latest reply on Nov 27, 2006 by Grzegorz Lysko
Hi
I'm curently using MC9S12NE64 (25Mhz oscilator + PLL configured by OpenTcp, SS pin not used from oryginal interface but connectec to one of PORTH's pins) with OpenTcp additional I wrote MMC suport based on SPI interface. Everything work's fine but it's slow... Acording to Datasheet my bound rate schould be 12Mhz but i'm geting about 245 kHz. I hope someone can help me becouse I have no ideas what could be wrong.

My SPI code:
#pragma CODE_SEG __NEAR_SEG NON_BANKED

void Init_spi(void)
{
DDRS_DDRS6=1;
DDRS_DDRS5=1;
CS_DIR=1;
PIEH=0x00;
SPICR1=0b01010000;
SPICR2=0x00;
//SPIBR=0b00010101;
SPIBR=0x00;

}

#pragma MESSAGE DISABLE C4000
tU08 send_byte(tU08 bajt)
{
while (SPISR_SPTEF==0);
SPIDR=bajt;
do
{
if (SPISR_SPIF==1)
return SPIDR;
} while (1);
}

#pragma MESSAGE DEFAULT C4000

#pragma CODE_SEG DEFAULT

Test procedure ( run_count is incremanted Every 1ms by internal timmer) :

extern unsigned long run_count;

volatile unsigned long start,stop,count;
start=run_count;
for (count=0;count1048576;count++)
send_byte(0xAA);
stop=run_count-start;

PLL config:
RTICTL = 44;
CLKSEL_PLLSEL = 0; /* Select clock source from XTAL */
SYNR = 0; /* Set the multiplier register */
REFDV = 0; /* Set the divider register */
PLLCTL |= 112; /* PLLCTL: PLLON=1,AUTO=1,ACQ=1 */
while(!CRGFLG_LOCK); /* Wait */
CLKSEL_PLLSEL = 1; /* Select clock source from PLL */


Thx for any help
Regards Kapsel

Message Edited by kapsel on 2006-11-2601:17 PM

Message Edited by kapsel on 2006-11-2601:17 PM

Outcomes