c problem

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View

i dont do c but need help in understanding what this bit of code does.
i am only interested in the  sendmmc() function.
does it send the command        Command(0x51,0,512,0xFF) then send 512 * ff
on spi bus
or send the comand 512 times ?


bit sendmmc()  // send 512 bytes from the MMC via the serial port
                                 uns16 i;
                                 // 512 byte-read-mode
                                 if (Command(0x51,0,512,0xFF) !=0) {
                                  SerString("MMC: read error 1 ");
                                  return 1;
                             while(SPI(0xFF) != 0xFE); // wait for 0xFE -
start of any transmission
i < 512; i++)
                              while(!TXIF);      // wait until TXREG is
                              TXREG = SPI(0xFF);  // get MMC byte and send
via RS232
 SPI(0xFF);      // at the end, send 2 dummy bytes
 return 0;

void main(void)
 InitUSART();     // initialize serial port
 initint();      // initialize interrupts

 ADCON1=0x6;      // PortA Digital
 // set ports for I/O
 TRISC = 0b.1101.0011;  // sck rc3-0, sdo rc5-0, CS rc2-0.
 TRISB = 0b.0000.0010;    // RB2>TX, RB1>RX

 SerString("PIC online "); // start message
// SerString(0x00); // start message

 // init MMC and send message if ok
 if (MMC_Init()) SerString("MMC online ");

 fillram();       // fill the RAM with ASCII characters
 writeramtommc();    // write RAM to MMC
 sendmmc();      // send 512 bytes of the MMC via serial port

 while(1) {

Re: c problem

snipped-for-privacy@fedup.com says...
Quoted text here. Click to load it
It sends the command, looks at the return code, and reports the error if
it occurred.  It appears that the command is sent once, but that is no
guarantee that the function Command(..) does not try more than once
before returning an error.

Quoted text here. Click to load it
Quoted text here. Click to load it
It looks like it then sends 512 bytes from the SPI to the serial port.

Quoted text here. Click to load it
It looks like the SPI peripheral needs two dummy bytes to finish the
transmission and be set for the next command.

That is my best guess without seeing the rest of the code.

Quoted text here. Click to load it

Site Timeline