Jump to content
Kotdnz

SSI and LM4F120XL

Recommended Posts

Hello,

 

Board LM4F120XL (LM4F120H5QR)

need Guru help with SPI.

 

Configuration:

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    ROM_GPIOPinConfigure(GPIO_PD3_SSI3TX);
    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_3);
    ROM_GPIOPinConfigure(GPIO_PD2_SSI3RX);
    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_2);
    ROM_GPIOPinConfigure(GPIO_PD0_SSI3CLK);
    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0);
    ROM_GPIOPinConfigure(GPIO_PD1_SSI3FSS);
    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_1);


    SSIConfigSetExpClk(SSI3_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
                       SSI_MODE_MASTER, SysCtlClockGet()/80, 8);
    SSIEnable(SSI3_BASE);
    // clear FIFO buffer
    unsigned long pui32DataRx;
    while(SSIDataGetNonBlocking(SSI3_BASE, &pui32DataRx))
    {
    }

And next function is read SPI:

static unsigned char Read_MFRC522(unsigned char addr)
{
    uint32_t val;

	RF_Activate();
 
	// Address format:1XXXXXX0
        val = ( addr << 1 ) & 0x80 ;
	SSIDataPut(OUR_SSI, val);
	while(SSIBusy(OUR_SSI));
  	SSIDataGet(OUR_SSI, &val);
  	while(SSIBusy(OUR_SSI));
 
	SSIDataPut(OUR_SSI, 0x00);
	while(SSIBusy(OUR_SSI));
  	SSIDataGet(OUR_SSI, &val);
  	while(SSIBusy(OUR_SSI));

	RF_Deactivate();
	return val;
}

due to datasheet when read device register 0x14 i must receive value 0x80, but by logic analyzer show next

post-3079-14264605405352_thumb.jpg 

My board send nothing.

But CS switched, CLK working, but on TX nothing.

 

May be i forget something?

My friend say it's defected IC.

 

Before SSI3 i try to use SSI0 base with same pure result.

Share this post


Link to post
Share on other sites

Hi,

Please review this expression:

val = ( addr << 1 ) & 0x80 ;

And-ing with 0x80 clears all seven bits in your val variable. Since neither the eight one was set after <<, you send always 0.

L

Share this post


Link to post
Share on other sites

Hi,

Your expression should be:

val = ( addr << 1 ) | 0x80 ;

for reading data - this is what the data sheet suggest:

The address byte must meet the following format.

The MSB of the first byte defines the mode used. To read data from the MFRC522 the MSB is set to logic 1. To write data to the MFRC522 the MSB must be set to logic 0. Bits 6 to 1 define the address and the LSB is set to logic 0.

Table 8. Address byte 0 register; address MOSI

1 = read 0 = write 

 

This is paragraph 8.1.2.3, page 11.

L

Share this post


Link to post
Share on other sites

Lyon,

 

My question about SPI.

Doesn't mater what rc522 reply.

Important - on command 

SSIDataPut(SSI3_BASE, 0xBA); 

logic analyzer show, that stellaris send ZERO.

Share this post


Link to post
Share on other sites

Hi,

Then maybe one solution to check your SPI configuration: use the PinMux utility to generate the code for you and compare it with yours. Also check if PD needs some commiting ( attention: PD7 is NMI).

Do not neglect some hardware problems - although I can see from the picture that SPI TX pin toggles.

L

Share this post


Link to post
Share on other sites

I already use PinMux.

 

My target is receive reply:

is trouble with SSI is a well know stallaris problem (or community know about defected series in the market) or it's only my private situation and require only optimize configuration.

 

 

In errata i found:

“Freescale SPI Mode at low SSIClk frequencies can yield data corruption”

Description:
Data transmitted by the SPI slave may be corrupted when using Freescale SPI Mode 0 at an SSIClk
frequency between 0.5 MHz to 1.1 MHz and a system clock frequency of 33 MHz or lower.
Workaround:
Operate the Freescale SPI Mode 0 at an SSIClk frequency above 1.1 MHz and use a system clock
frequency above 33 MHz or use a different mode.

 

P.S. my system clock speed is 80MHz

SysCtlClockSet(SYSCTL_USE_PLL | SYSCTL_SYSDIV_2_5 | SYSCTL_OSC_MAIN |
                    SYSCTL_XTAL_16MHZ);
 
and i use RTC.

Share this post


Link to post
Share on other sites

Hi,

I realized you use the system clock at 80MHz and SPI clock at 1MHz so if that observation is really for TM4C123x micros, then you may be in that particular nasty situation. Why not try to increase to 2MHz? Can you also change to mode 3?

Also, you said "and i use RTC." What should I understand for that? Are you in hibernating mode when calling SPI reading?

L

Share this post


Link to post
Share on other sites

Hi,

 

I check is this clock setup working by invoke SysCtlClockGet and return 80'000'000.

My device can run up to 10MHz, so i can use faster SPI.

Are you mean change to mode 3 - Motorola code?

So final SPI config may look like

SSIConfigSetExpClk(SSI3_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_3SSI_MODE_MASTER, 5000000, 8);

 

About RTC - when we told about clock speed and they effect to system i initialize RTC via next code:


  //Realtime Clock and hibernate
  ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);
  // clear data
  HWREG(HIB_CTL) |= HIB_CTL_CLK32EN | HIB_CTL_OSCDRV;
  // Delay for the maximum crystal oscillator start-up time of 1500ms
  ROM_SysCtlDelay (1500 * (ROM_SysCtlClockGet() / 3 / 1000));
  ROM_HibernateRTCSet (0);
 
  ROM_HibernateEnableExpClk(ROM_SysCtlClockGet()); //must be called first have a look page at 458 (spms294e.pdf)
  HibernateClockConfig(HIBERNATE_OSC_DISABLE | HIBERNATE_OSC_HIGHDRIVE); //select the external crystal with 24pF filter capacitor (for launchpad lm4f120xl)
  HibernateClockSelect(HIBERNATE_CLOCK_SEL_RAW); //select the raw output of the 32khz crystal
  HibernateRTCTrimSet(0x7FFF); // must be called. if you don't set manually the trim register, the counter counts too fast or too slow have a look at page 462 (spsm294e.pdf)
  HibernateGPIORetentionEnable();
  ROM_HibernateWakeSet(HIBERNATE_WAKE_PIN);
  ROM_SysCtlDelay(6400); //necessary, without this rtc won't work. don't really know why
  ROM_HibernateRTCEnable();

Share this post


Link to post
Share on other sites

Hi,

You got it - for mode 3 -it is what I meant.

As for RTC - if you do not need it, do not add that code. Also do not move it in hibernation mode when you need to use the SPI.

L

Share this post


Link to post
Share on other sites

Oops... Thank you - it's look like solution.

May be i release RTC by simple timer with unix_time.

Is it possible count ticks in timer interrupt based on 32KHz RT crystall?

 

Thanks again, hope returned to me.

Share this post


Link to post
Share on other sites

Hi,

One more important thing: the spma289.pdf document (Launchpad document/schematic) shows the PD0 connected to PB6 with R9=0 ohms and PD1 connected to PB7 with R10=0 ohms. If you have another signals on PBx pins, remove R9 and R10.

 

Not clear what you to intend to do with RTC - what are your needs - either a watch/clock or something else.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...