Loading ...
Sorry, an error occurred while loading the content.

SPI interface configuration

Expand Messages
  • katagia
    Hi I want to connect a sd card to spi. The code itself is working. Here is a short part of the interrupt function: case 9: SPITX = 0xFF;
    Message 1 of 2 , Feb 23, 2008
    • 0 Attachment
      Hi

      I want to connect a sd card to spi. The code itself is working.
      Here is a short part of the interrupt function:

      case 9:
      SPITX = 0xFF;
      disk_timerproc_state++;
      break;
      case 10:
      while (!(SPISTA & 0x04)) {}; // Wait until byte has been
      received
      disk_timerproc_buff[5] = SPIRX;
      if ((disk_timerproc_buff[5] & 0x40) && workspace--) { // no
      response received. R1 response starts with 0....
      SPITX = 0xFF; // Send dummy
      }
      else {
      disk_timerproc_clr = SPI_MASTER_BIT;
      }
      break;

      As you can see there is a while loop waiting until the byte has been
      received. When TX is empty an interrupt is generated.
      TX-Empty doesn't mean RX is full. Therefore the function has to wait
      until RX is ready.

      I want to get rid of the while-loops in the interrupt function. My idea
      was to change interrupt generation from TX-Empty
      to RX-Full by clearing Bit6 of SPICON. This is the changed code:

      case 9:
      SPITX = 0xFF;
      SPICON = 0x100B; // switch irq to rx-full
      disk_timerproc_state++;
      break;
      case 10:
      disk_timerproc_buff[5] = SPIRX;
      if ((disk_timerproc_buff[5] & 0x40) && workspace--) { // no
      response received. R1 response starts with 0....
      SPITX = 0xFF; // Send dummy
      }
      else {
      SPICON = 0x104B; // switch irq to tx-empty
      disk_timerproc_clr = SPI_MASTER_BIT;
      }
      break;



      Unfortunatly "case 10" isn't reached anymore. There is no interrupt when
      RX should be full.

      Where is my mistake?
      Any hints?

      Cheers, Tilo
    • paloalgodon
      ... We had a related issue last year. The timing of the handshake flags in the ADuC is non-standard, if usable at all. I think we had to resort to using the
      Message 2 of 2 , Mar 4, 2008
      • 0 Attachment
        --- In ADuC_ARM@yahoogroups.com, "katagia" <TiloLutz@...> wrote:
        >
        > Hi
        >
        > I want to connect a sd card to spi. The code itself is working.
        > Here is a short part of the interrupt function:
        >
        > case 9:
        > SPITX = 0xFF;
        > disk_timerproc_state++;
        > break;
        > case 10:
        > while (!(SPISTA & 0x04)) {}; // Wait until byte has been
        > received
        > disk_timerproc_buff[5] = SPIRX;
        > if ((disk_timerproc_buff[5] & 0x40) && workspace--) { // no
        > response received. R1 response starts with 0....
        > SPITX = 0xFF; // Send dummy
        > }
        > else {
        > disk_timerproc_clr = SPI_MASTER_BIT;
        > }
        > break;
        >
        > As you can see there is a while loop waiting until the byte has been
        > received. When TX is empty an interrupt is generated.
        > TX-Empty doesn't mean RX is full. Therefore the function has to wait
        > until RX is ready.
        >
        > I want to get rid of the while-loops in the interrupt function. My idea
        > was to change interrupt generation from TX-Empty
        > to RX-Full by clearing Bit6 of SPICON. This is the changed code:
        >
        > case 9:
        > SPITX = 0xFF;
        > SPICON = 0x100B; // switch irq to rx-full
        > disk_timerproc_state++;
        > break;
        > case 10:
        > disk_timerproc_buff[5] = SPIRX;
        > if ((disk_timerproc_buff[5] & 0x40) && workspace--) { // no
        > response received. R1 response starts with 0....
        > SPITX = 0xFF; // Send dummy
        > }
        > else {
        > SPICON = 0x104B; // switch irq to tx-empty
        > disk_timerproc_clr = SPI_MASTER_BIT;
        > }
        > break;
        >
        >
        >
        > Unfortunatly "case 10" isn't reached anymore. There is no interrupt when
        > RX should be full.
        >
        > Where is my mistake?
        > Any hints?
        >
        > Cheers, Tilo
        >

        We had a related issue last year. The timing of the handshake flags
        in the ADuC is non-standard, if usable at all. I think we had to
        resort to using the TX flag for all cases. We actually got the RX
        flag but it was in the middle (!) of the byte, not the end, suggesting
        a non-causal system! I suggest you maybe pull out an oscilloscope,
        and toggle some pins to debug the timing. In any event, SPI sends and
        receives at the same time, so the extra flags are extraneous.

        Steve
      Your message has been successfully submitted and would be delivered to recipients shortly.