Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help coding PEC byte
24-04-2012, 09:44 PM,
RE: Help coding PEC byte
Hi Dale,

from your various posts you appear to have both PIC32 Pinguino OTG and PIC32 Pinguino Micro boards - is it worth trying to run just the SPI code on your OTG board? (See also below)

Also looking at documentation for both boards, they both share the ports/registers used for SPI (RG6, RG7, RG8 & RG9) among a number of external connectors. Both boards have ports/registers RG6, RG7 & RG8 connected to both the UEXT connector and the micro SD connector and on the OTG board they are also shared with D13, D12 & D11. It might be worth checking that no other functions you are using directly (or indirectly) are trying to access these ports/registers or any other ones that use the same IC pins (IC Pins 4, 5, 6 & 8).

I think you managed to get the SD library running on your OTG board - the SD library uses SPI functions to talk to the SD card - it might be worth looking at the code in sdmmc.c/sdmmc.h files for ideas about using the SPI functions.

Board = PIC32-Pinguino-OTG Rev C
OS = Linux Unbuntu 11.10 till 26 Apr 2012
OS = Linux Unbuntu 12:04 from 27 Apr 2012
25-04-2012, 12:49 AM, (This post was last modified: 25-04-2012, 02:26 AM by KiloOne.)
Error in x.3 i2c.c
Well that was a few hours of intense learning and I think it boils down to a {} problem in i2c.c.

First of all my i2c write data was not on the SPI pins. That took me to investigating i2c.c. Eventually I discovered that SPI2BRG was always coming out as 0 no matter what you put into the SPI_clock() function.

Using the little amount of error trapping I have available, I determined that the missing {} of the if (clk > 511) condition was the culprit. The error was causing execution to jump back to the calling location without ever setting CLKSPD (unless you asked for a crazy speed to begin with) and a CLKSPD of 0 gives a 20mhz clock or more which doesn't seem to work.

Funny I was specifically questioning what I have been seeing in code, not having {} in a 2 line condition. I assumed the code was attached for just one more line if you don't use them but the 'return' here is on the 3rd line, ooops. I think that is easy to do unless you use {} all the time in all more than 1 line conditions.

Actually, if I am right, I am not sure how anyone got a non zero CLKSPD.

Here is the code for the SPI_clock() function that works for me:
void SPI_clock(u32 speed)
    u32 Fpb;
    u32 Fsck;
    u16 clk;

    Fpb = GetPeripheralClock();
    if (speed > (Fpb / 2))
        CLKSPD = 0;        // use the maximum baud rate possible
        clk = (Fpb / (2 * speed)) - 1;
        if (clk > 511)
        {                    // { added by dk
            CLKSPD = 511;    // use the minimum baud rate possible
        }                    // } added by dk
        CLKSPD = clk;

Can I have a break now?

Nope, on to the decoding.Shy

PIC32-Pinguino-OTG Rev C and PIC32-PINGUINO-MICRO rev.B
Win XP SP3
r381 x.3 Big Grin
AND spi.c {} error fixed
AND sdmmc.c pin error fixed
AND diskio.c fixed, MICRO can't use the RTCC
AND analog.c fixed for MICRO

Forum Jump:

Users browsing this thread: 1 Guest(s)