SHIFTOUT problems on Atom 28 Pro

I was told to use the Pro IDE ver 8.0.1.3 beta and here are the results.

I tested the DTMFOUT command and there are no errors, but it does not produce sound.
dtmfout 9,[1,2,3,4]

DTMFOUT2 works.
dtmfout2 9\10,[1,2,3,4]

FREQOUT works.
freqout 9,1000,1500

SOUND works.
sound 9,[1000\1500]

SOUND2 works.
sound2 9\10,[1000\1500\1600]

PWM works
pwm 9,20000,10000,1000

I tried HPWM. No errors but no sound.
hpwm 9,20000,10000

Ok, so the HPWM only works on pins 10, 11, and 12. So the only known issues are with DTMFOUT and possibly SHIFTOUT. Sorry for the thread jack. I’m starting a new Pro 8.0.1.3 Beta thread.

thanks for the confirmation on the sound Robot Dude

As for SHIFTOUT got the cro today and had a look at the signal. as far as i can tell the micro is outputting the correct signal. i can’t tell if the timing is correct because the cro i scored is one of the old ones uni was giving away. anyway, my understanding is that even if the timing is not correct the LCD should still read something at the CLK time, even if its 0x00 or 0xF5. correct?
anyway here is the code i used and analysed the signal.

low P0 ;CS low P1 pause 10 shiftout P2,P1,msbpre,[255] ;sync command shiftout P2,P1,msbpre,[129] ;backlight off pause 10

any suggestions? i’m all out of ideas

hey guys,

i know its a big ask, but can someone look over this source code written in C? forum.modtronix.com/index.php?topic=399.0 its been a few years since i have touched C…
as i understand it IDE supports C, right?

Modtronix says this will definitely work.

Here is a quick build of some of this code. You start off in the ide and do a create new project. Make sure to select C and C++ project type. In my case I called the project SPI. Please note, I simply made it compile, I have not tried running it on my machine. Your milage may very…

Here is a version of the file: spi.cpp

[code]extern “C” {
#include “3664s.h”
}

//Define all SPI Pins

#define SPI_OUT IO.PDR5.BIT.B7
#define SPI_IN IO.PDR5.BIT.B6
#define SPI_CLK IO.PDR5.BIT.B5
#define SPI_CS IO.PDR5.BIT.B4

/**

  • This function writes a byte out onto the SPI OUT port, and reads a byte from
  • the SPI IN port.
  • @param c Gives the byte to write out onto the SPI port
  • @return Returns the byte read from the SPI IN port
    */

void Nop()
{
int i;
for (i=0; i<100; i++)
{
;
}
}

char spiPutGetByte(char c) {
char ret;
unsigned char mask;

//SPI Mode 0. CS active low. Clock idle 0. Clock rising edge.
SPI_CLK = 0;

//Enable SPI communication. The SPI Enable signal must be pulsed low for each byte sent!
SPI_CS = 0;

//Ensure a minimum delay of 500ns between falling edge of SPI Enable signal
//and rising edge of SPI Clock!
Nop();
mask = 0x80;                //Initialize to write and read bit 7
ret = 0;                    //Initialize read byte with 0

do  {
    SPI_OUT = 0;                //Clock out current bit onto SPI Out line
    if (c & mask) SPI_OUT = 1;
    SPI_CLK = 1;                //Set SPI Clock line
    if (SPI_IN) ret |= mask;    //Read current bit fromSPI In line
    Nop();                      //Ensure minimum delay of 500nS between SPI Clock high and SPI Clock Low
    SPI_CLK = 0;                //Set SPI Clock line
    mask = mask >> 1;           //Shift mask so that next bit is written and read from SPI lines
    Nop();                      //Ensure minimum delay of 1000ns between bits
} while (mask != 0);


//Ensure a minimum delay of 750ns between falling edge of SPI Clock signal
//and rising edge of SPI Enable!
Nop();Nop();

//Disable SPI communication. The SPI Enable signal must be pulsed low for each byte sent!
SPI_CS = 1;

return ret;

}

int main(void)
{
spiPutGetByte(0xf5); //Sync byte - each SPI command has to start with this byte!
spiPutGetByte(0x80); //“Write parsed string command”
spiPutGetByte(0x0c); //Clear display and go to beginning of first line.

//Write "Hello" in line one, and "World" in line two
spiPutGetByte('H');
spiPutGetByte('e');
spiPutGetByte('l');
spiPutGetByte('l');
spiPutGetByte('o');
spiPutGetByte(0x0a);   //Go to beginning of next line
spiPutGetByte('W');
spiPutGetByte('o');
spiPutGetByte('r');
spiPutGetByte('l');
spiPutGetByte('d');

}[/code]

Now through an earlier time when I was playing with the C++ had a version of the include file I show above that made it easier to deal with the hardware registers. I include it here in case anyone wishes to use it…

It is called 3664s.h

/************************************************************************/
/*      H8/3664 Series Include File                        Ver 2.0      */
/************************************************************************/
struct st_flash {                                       /* struct FLASH */
                union {                                 /* FLMCR1       */
                      unsigned char BYTE;               /*  Byte Access */
                      struct {                          /*  Bit  Access */
                             unsigned char    :1;       /*              */
                             unsigned char SWE:1;       /*    SWE       */
                             unsigned char ESU:1;       /*    ESU       */
                             unsigned char PSU:1;       /*    PSU       */
                             unsigned char EV :1;       /*    EV        */
                             unsigned char PV :1;       /*    PV        */
                             unsigned char E  :1;       /*    E         */
                             unsigned char P  :1;       /*    P         */
                             }      BIT;                /*              */
                      }         FLMCR1;                 /*              */
                union {                                 /* FLMCR2       */
                      unsigned char BYTE;               /*  Byte Access */
                      struct {                          /*  Bit  Access */
                             unsigned char FLER:1;      /*    FLER      */
                             }      BIT;                /*              */
                      }         FLMCR2;                 /*              */
                union {                                 /* FLPWCR       */
                      unsigned char BYTE;               /*  Byte Access */
                      struct {                          /*  Bit  Access */
                             unsigned char PDWND:1;     /*    PDWND     */
                             }      BIT;                /*              */
                      }         FLPWCR;                 /*              */
                union {                                 /* EBR1         */
                      unsigned char BYTE;               /*  Byte Access */
                      struct {                          /*  Bit  Access */
                             unsigned char    :3;       /*              */
                             unsigned char EB4:1;       /*    EB4       */
                             unsigned char EB3:1;       /*    EB3       */
                             unsigned char EB2:1;       /*    EB2       */
                             unsigned char EB1:1;       /*    EB1       */
                             unsigned char EB0:1;       /*    EB0       */
                             }      BIT;                /*              */
                      }         EBR1;                   /*              */
                char            wk[7];                  /*              */
                union {                                 /* FENR         */
                      unsigned char BYTE;               /*  Byte Access */
                      struct {                          /*  Bit  Access */
                             unsigned char FLSHE:1;     /*    FLSHE     */
                             }      BIT;                /*              */
                      }         FENR;                   /*              */
};                                                      /*              */
struct st_ta {                                          /* struct TA    */
             union {                                    /* TMA          */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char CKSO:3;         /*    CKSO      */
                          unsigned char     :1;         /*              */
                          unsigned char CKSI:4;         /*    CKSI      */
                          }      BIT;                   /*              */
                   }            TMA;                    /*              */
             unsigned char      TCA;                    /* TCA          */
};                                                      /*              */
struct st_tv {                                          /* struct TV    */
             union {                                    /* TCRV0        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char CMIEB:1;        /*    CMIEB     */
                          unsigned char CMIEA:1;        /*    CMIEA     */
                          unsigned char OVIE :1;        /*    OVIE      */
                          unsigned char CCLR :2;        /*    CCLR      */
                          unsigned char CKS  :3;        /*    CKS       */
                          }      BIT;                   /*              */
                   }            TCRV0;                  /*              */
             union {                                    /* TCSRV        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char CMFB:1;         /*    CMFB      */
                          unsigned char CMFA:1;         /*    CMFA      */
                          unsigned char OVF :1;         /*    OVF       */
                          unsigned char     :1;         /*              */
                          unsigned char OS  :4;         /*    OS        */
                          }      BIT;                   /*              */
                   }            TCSRV;                  /*              */
             unsigned char      TCORA;                  /* TCORA        */
             unsigned char      TCORB;                  /* TCORB        */
             unsigned char      TCNTV;                  /* TCNT         */
             union {                                    /* TCRV1        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char     :3;         /*              */
                          unsigned char TVEG:2;         /*    TVEG      */
                          unsigned char TRGE:1;         /*    TRGE      */
                          unsigned char     :1;         /*              */
                          unsigned char ICKS:1;         /*    ICKS      */
                          }      BIT;                   /*              */
                   }            TCRV1;                  /*              */
};                                                      /*              */
struct st_tw {                                          /* struct TW    */
             union {                                    /* TMRW         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char CTS  :1;        /*    CTS       */
                          unsigned char      :1;        /*              */
                          unsigned char BUFEB:1;        /*    BUFEB     */
                          unsigned char BUFEA:1;        /*    BUFEA     */
                          unsigned char      :1;        /*              */
                          unsigned char PWMD :1;        /*    PWMD      */
                          unsigned char PWMC :1;        /*    PWMC      */
                          unsigned char PWMB :1;        /*    PWMB      */
                          }      BIT;                   /*              */
                   }            TMRW;                   /*              */
             union {                                    /* TCRW         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char CCLR:1;         /*    CCLR      */
                          unsigned char CKS :3;         /*    CKS       */
                          unsigned char TOD :1;         /*    TOD       */
                          unsigned char TOC :1;         /*    TOC       */
                          unsigned char TOB :1;         /*    TOB       */
                          unsigned char TOA :1;         /*    TOA       */
                          }      BIT;                   /*              */
                   }            TCRW;                   /*              */
             union {                                    /* TIERW        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char OVIE :1;        /*    OVIE      */
                          unsigned char      :3;        /*              */
                          unsigned char IMIED:1;        /*    IMIED     */
                          unsigned char IMIEC:1;        /*    IMIEC     */
                          unsigned char IMIEB:1;        /*    IMIEB     */
                          unsigned char IMIEA:1;        /*    IMIEA     */
                          }      BIT;                   /*              */
                   }            TIERW;                  /*              */
             union {                                    /* TSRW         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char OVF :1;         /*    OVF       */
                          unsigned char     :3;         /*              */
                          unsigned char IMFD:1;         /*    IMFD      */
                          unsigned char IMFC:1;         /*    IMFC      */
                          unsigned char IMFB:1;         /*    IMFB      */
                          unsigned char IMFA:1;         /*    IMFA      */
                          }      BIT;                   /*              */
                   }            TSRW;                   /*              */
             union {                                    /* TIOR0        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char    :1;          /*              */
                          unsigned char IOB:3;          /*    IOB       */
                          unsigned char    :1;          /*              */
                          unsigned char IOA:3;          /*    IOA       */
                          }      BIT;                   /*              */
                   }            TIOR0;                  /*              */
             union {                                    /* TIOR1        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char    :1;          /*              */
                          unsigned char IOD:3;          /*    IOD       */
                          unsigned char    :1;          /*              */
                          unsigned char IOC:3;          /*    IOC       */
                          }      BIT;                   /*              */
                   }            TIOR1;                  /*              */
             unsigned int       TCNT;                   /* TCNT         */
             unsigned int       GRA;                    /* GRA          */
             unsigned int       GRB;                    /* GRB          */
             unsigned int       GRC;                    /* GRC          */
             unsigned int       GRD;                    /* GRD          */
};                                                      /*              */
struct st_sci3 {                                        /* struct SCI3  */
               union {                                  /* SMR          */
                     unsigned char BYTE;                /*  Byte Access */
                     struct {                           /*  Bit  Access */
                            unsigned char COM :1;       /*    COM       */
                            unsigned char CHR :1;       /*    CHR       */
                            unsigned char PE  :1;       /*    PE        */
                            unsigned char PM  :1;       /*    PM        */
                            unsigned char STOP:1;       /*    STOP      */
                            unsigned char MP  :1;       /*    MP        */
                            unsigned char CKS :2;       /*    CKS       */
                            }      BIT;                 /*              */
                     }          SMR;                    /*              */
               unsigned char    BRR;                    /* BRR          */
               union {                                  /* SCR3         */
                     unsigned char BYTE;                /*  Byte Access */
                     struct {                           /*  Bit  Access */
                            unsigned char TIE :1;       /*    TIE       */
                            unsigned char RIE :1;       /*    RIE       */
                            unsigned char TE  :1;       /*    TE        */
                            unsigned char RE  :1;       /*    RE        */
                            unsigned char MPIE:1;       /*    MPIE      */
                            unsigned char TEIE:1;       /*    TEIE      */
                            unsigned char CKE :2;       /*    CKE       */
                            }      BIT;                 /*              */
                     }          SCR3;                   /*              */
               unsigned char    TDR;                    /* TDR          */
               union {                                  /* SSR          */
                     unsigned char BYTE;                /*  Byte Access */
                     struct {                           /*  Bit  Access */
                            unsigned char TDRE:1;       /*    TDRE      */
                            unsigned char RDRF:1;       /*    RDRF      */
                            unsigned char OER :1;       /*    OER       */
                            unsigned char FER :1;       /*    FER       */
                            unsigned char PER :1;       /*    PER       */
                            unsigned char TEND:1;       /*    TEND      */
                            unsigned char MPBR:1;       /*    MPBR      */
                            unsigned char MPBT:1;       /*    MPBT      */
                            }      BIT;                 /*              */
                     }          SSR;                    /*              */
               unsigned char    RDR;                    /* RDR          */
};                                                      /*              */
struct st_ad {                                          /* struct A/D   */
             unsigned int       ADDRA;                  /* ADDRA        */
             unsigned int       ADDRB;                  /* ADDRB        */
             unsigned int       ADDRC;                  /* ADDRC        */
             unsigned int       ADDRD;                  /* ADDRD        */
             union {                                    /* ADCSR        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char ADF :1;         /*    ADF       */
                          unsigned char ADIE:1;         /*    ADIE      */
                          unsigned char ADST:1;         /*    ADST      */
                          unsigned char SCAN:1;         /*    SCAN      */
                          unsigned char CKS :1;         /*    CKS       */
                          unsigned char CH  :3;         /*    CH        */
                          }      BIT;                   /*              */
                   }            ADCSR;                  /*              */
             union {                                    /* ADCR         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char TRGE:1;         /*    TRGE      */
                          }      BIT;                   /*              */
                   }            ADCR;                   /*              */
};                                                      /*              */
struct st_wdt {                                         /* struct WDT   */
              union {                                   /* TCSRWD       */
                    unsigned char BYTE;                 /*  Byte Access */
                    struct {                            /*  Bit  Access */
                           unsigned char B6WI  :1;      /*    B6WI      */
                           unsigned char TCWE  :1;      /*    TCWE      */
                           unsigned char B4WI  :1;      /*    B4WI      */
                           unsigned char TCSRWE:1;      /*    TCSRWE    */
                           unsigned char B2WI  :1;      /*    B2WI      */
                           unsigned char WDON  :1;      /*    WDON      */
                           unsigned char B0WI  :1;      /*    B0WI      */
                           unsigned char WRST  :1;      /*    WRST      */
                           }      BIT;                  /*              */
                    }           TCSRWD;                 /*              */
              unsigned char     TCWD;                   /* TCWD         */
              union {                                   /* TMWD         */
                    unsigned char BYTE;                 /*  Byte Access */
                    struct {                            /*  Bit  Access */
                           unsigned char    :4;         /*              */
                           unsigned char CKS:4;         /*    CKS       */
                           }      BIT;                  /*              */
                    }           TMWD;                   /*              */
};                                                      /*              */
struct st_iic {                                         /* struct IIC   */
              union {                                   /* ICCR         */
                    unsigned char BYTE;                 /*  Byte Access */
                    struct {                            /*  Bit  Access */
                           unsigned char ICE :1;        /*    ICE       */
                           unsigned char IEIC:1;        /*    IEIC      */
                           unsigned char MST :1;        /*    MST       */
                           unsigned char TRS :1;        /*    TRS       */
                           unsigned char ACKE:1;        /*    ACKE      */
                           unsigned char BBSY:1;        /*    BBSY      */
                           unsigned char IRIC:1;        /*    IRIC      */
                           unsigned char SCP :1;        /*    SCP       */
                           }      BIT;                  /*              */
                    }           ICCR;                   /*              */
              union {                                   /* ICSR         */
                    unsigned char BYTE;                 /*  Byte Access */
                    struct {                            /*  Bit  Access */
                           unsigned char ESTP:1;        /*    ESTP      */
                           unsigned char STOP:1;        /*    STOP      */
                           unsigned char IRTR:1;        /*    IRTR      */
                           unsigned char AASX:1;        /*    AASX      */
                           unsigned char AL  :1;        /*    AL        */
                           unsigned char AAS :1;        /*    AAS       */
                           unsigned char ADZ :1;        /*    ADZ       */
                           unsigned char ACKB:1;        /*    ACKB      */
                           }      BIT;                  /*              */
                    }           ICSR;                   /*              */
              union {                                   /*              */
                    struct {                            /*              */
                           union {                      /* SARX         */
                                 unsigned char BYTE;    /*  Byte Access */
                                 struct {               /*  Bit  Access */
                                        unsigned char SVAX:7; /* SVAX   */
                                        unsigned char FSX :1; /* FSX    */
                                        }      BIT;     /*              */
                                 } UN_SARX;             /*              */
                           union {                      /* SAR          */
                                 unsigned char BYTE;    /*  Byte Access */
                                 struct {               /*  Bit  Access */
                                        unsigned char SVA:7; /* SVA     */
                                        unsigned char FS :1; /* FS      */
                                        }      BIT;     /*              */
                                 } UN_SAR;              /*              */
                           } ICE0;                      /*              */
                    struct {                            /*              */
                           unsigned char UN_ICDR;       /* ICDR         */
                           union {                      /* ICMR         */
                                 unsigned char BYTE;    /*  Byte Access */
                                 struct {               /*  Bit  Access */
                                        unsigned char MLS :1; /* MLS    */
                                        unsigned char WAIT:1; /* WAIT   */
                                        unsigned char CKS :3; /* CKS    */
                                        unsigned char BC  :3; /* BC     */
                                        }      BIT;     /*              */
                                 }       UN_ICMR;       /*              */
                           } ICE1;                      /*              */
                    }           EQU;                    /*              */
};                                                      /*              */
struct st_abrk {                                        /* struct ABRK  */
               union {                                  /* ABRKCR       */
                     unsigned char BYTE;                /*  Byte Access */
                     struct {                           /*  Bit  Access */
                            unsigned char RTINTE:1;     /*    RTINTE    */
                            unsigned char CSEL  :2;     /*    CSEL      */
                            unsigned char ACMP  :3;     /*    ACMP      */
                            unsigned char DCMP  :2;     /*    DCMP      */
                            }      BIT;                 /*              */
                     }          CR;                     /*              */
               union {                                  /* ABRKSR       */
                     unsigned char BYTE;                /*  Byte Access */
                     struct {                           /*  Bit  Access */
                            unsigned char ABIF:1;       /*    ABIF      */
                            unsigned char ABIE:1;       /*    ABIE      */
                            }      BIT;                 /*              */
                     }          SR;                     /*              */
               void            *BAR;                    /* BAR          */
               unsigned int     BDR;                    /* BDR          */
};                                                      /*              */
struct st_io {                                          /* struct IO    */
             union {                                    /* PUCR1        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char B7:1;           /*    Bit 7     */
                          unsigned char B6:1;           /*    Bit 6     */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          unsigned char   :1;           /*    Bit 3     */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PUCR1;                  /*              */
             union {                                    /* PUCR5        */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char   :2;           /*    Bit 7,6   */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          unsigned char B3:1;           /*    Bit 3     */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PUCR5;                  /*              */
             char               wk1[2];                 /*              */
             union {                                    /* PDR1         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char B7:1;           /*    Bit 7     */
                          unsigned char B6:1;           /*    Bit 6     */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          unsigned char   :1;           /*    Bit 3     */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PDR1;                   /*              */
             union {                                    /* PDR2         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char   :5;           /*    Bit 7-3   */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PDR2;                   /*              */
             char               wk2[2];                 /*              */
             union {                                    /* PDR5         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char B7:1;           /*    Bit 7     */
                          unsigned char B6:1;           /*    Bit 6     */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          unsigned char B3:1;           /*    Bit 3     */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PDR5;                   /*              */
             char               wk3;                    /*              */
             union {                                    /* PDR7         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char   :1;           /*    Bit 7     */
                          unsigned char B6:1;           /*    Bit 6     */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          }      BIT;                   /*              */
                   }            PDR7;                   /*              */
             union {                                    /* PDR8         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char B7:1;           /*    Bit 7     */
                          unsigned char B6:1;           /*    Bit 6     */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          unsigned char B3:1;           /*    Bit 3     */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PDR8;                   /*              */
             char               wk4;                    /*              */
             union {                                    /* PDRB         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char B7:1;           /*    Bit 7     */
                          unsigned char B6:1;           /*    Bit 6     */
                          unsigned char B5:1;           /*    Bit 5     */
                          unsigned char B4:1;           /*    Bit 4     */
                          unsigned char B3:1;           /*    Bit 3     */
                          unsigned char B2:1;           /*    Bit 2     */
                          unsigned char B1:1;           /*    Bit 1     */
                          unsigned char B0:1;           /*    Bit 0     */
                          }      BIT;                   /*              */
                   }            PDRB;                   /*              */
             char               wk5[2];                 /*              */
             union {                                    /* PMR1         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char IRQ3:1;         /*    IRQ3      */
                          unsigned char IRQ2:1;         /*    IRQ2      */
                          unsigned char IRQ1:1;         /*    IRQ1      */
                          unsigned char IRQ0:1;         /*    IRQ0      */
                          unsigned char     :2;         /*              */
                          unsigned char TXD :1;         /*    TXD       */
                          unsigned char TMOW:1;         /*    TMOW      */
                          }      BIT;                   /*              */
                   }            PMR1;                   /*              */
             union {                                    /* PMR5         */
                   unsigned char BYTE;                  /*  Byte Access */
                   struct {                             /*  Bit  Access */
                          unsigned char     :2;         /*              */
                          unsigned char WKP5:1;         /*    WKP5      */
                          unsigned char WKP4:1;         /*    WKP4      */
                          unsigned char WKP3:1;         /*    WKP3      */
                          unsigned char WKP2:1;         /*    WKP2      */
                          unsigned char WKP1:1;         /*    WKP1      */
                          unsigned char WKP0:1;         /*    WKP0      */
                          }      BIT;                   /*              */
                   }            PMR5;                   /*              */
             char               wk6[2];                 /*              */
             unsigned char      PCR1;                   /* PCR1         */
             unsigned char      PCR2;                   /* PCR2         */
             char               wk7[2];                 /*              */
             unsigned char      PCR5;                   /* PCR5         */
             char               wk8;                    /*              */
             unsigned char      PCR7;                   /* PCR7         */
             unsigned char      PCR8;                   /* PCR8         */
};                                                      /*              */
union un_syscr1 {                                       /* union SYSCR1 */
                unsigned char BYTE;                     /*  Byte Access */
                struct {                                /*  Bit  Access */
                       unsigned char SSBY :1;           /*    SSBY      */
                       unsigned char STS  :3;           /*    STS       */
                       unsigned char NESEL:1;           /*    NESEL     */
                       }      BIT;                      /*              */
};                                                      /*              */
union un_syscr2 {                                       /* union SYSCR2 */
                unsigned char BYTE;                     /*  Byte Access */
                struct {                                /*  Bit  Access */
                       unsigned char SMSEL:1;           /*    SMSEL     */
                       unsigned char LSON :1;           /*    LSON      */
                       unsigned char DTON :1;           /*    DTON      */
                       unsigned char MA   :3;           /*    MA        */
                       unsigned char SA   :2;           /*    SA        */
                       }      BIT;                      /*              */
};                                                      /*              */
union un_iegr1 {                                        /* union IEGR1  */
               unsigned char BYTE;                      /*  Byte Access */
               struct {                                 /*  Bit  Access */
                      unsigned char NMIEG:1;            /*    NMIEG     */
                      unsigned char      :3;            /*              */
                      unsigned char IEG3 :1;            /*    IEG3      */
                      unsigned char IEG2 :1;            /*    IEG2      */
                      unsigned char IEG1 :1;            /*    IEG1      */
                      unsigned char IEG0 :1;            /*    IEG0      */
                      }      BIT;                       /*              */
};                                                      /*              */
union un_iegr2 {                                        /* union IEGR2  */
               unsigned char BYTE;                      /*  Byte Access */
               struct {                                 /*  Bit  Access */
                      unsigned char      :2;            /*              */
                      unsigned char WPEG5:1;            /*    WPEG5     */
                      unsigned char WPEG4:1;            /*    WPEG4     */
                      unsigned char WPEG3:1;            /*    WPEG3     */
                      unsigned char WPEG2:1;            /*    WPEG2     */
                      unsigned char WPEG1:1;            /*    WPEG1     */
                      unsigned char WPEG0:1;            /*    WPEG0     */
                      }      BIT;                       /*              */
};                                                      /*              */
union un_ienr1 {                                        /* union IENR1  */
               unsigned char BYTE;                      /*  Byte Access */
               struct {                                 /*  Bit  Access */
                      unsigned char IENDT:1;            /*    IENDT     */
                      unsigned char IENTA:1;            /*    IENTA     */
                      unsigned char IENWP:1;            /*    IENWP     */
                      unsigned char      :1;            /*              */
                      unsigned char IEN3 :1;            /*    IEN3      */
                      unsigned char IEN2 :1;            /*    IEN2      */
                      unsigned char IEN1 :1;            /*    IEN1      */
                      unsigned char IEN0 :1;            /*    IEN0      */
                      }      BIT;                       /*              */
};                                                      /*              */
union un_irr1 {                                         /* union IRR1   */
              unsigned char BYTE;                       /*  Byte Access */
              struct {                                  /*  Bit  Access */
                     unsigned char IRRDT:1;             /*    IRRDT     */
                     unsigned char IRRTA:1;             /*    IRRTA     */
                     unsigned char      :2;             /*              */
                     unsigned char IRRI3:1;             /*    IRRI3     */
                     unsigned char IRRI2:1;             /*    IRRI2     */
                     unsigned char IRRI1:1;             /*    IRRI1     */
                     unsigned char IRRI0:1;             /*    IRRI0     */
                     }      BIT;                        /*              */
};                                                      /*              */
union un_iwpr {                                         /* union IWPR   */
              unsigned char BYTE;                       /*  Byte Access */
              struct {                                  /*  Bit  Access */
                     unsigned char      :2;             /*              */
                     unsigned char IWPF5:1;             /*    IWPF5     */
                     unsigned char IWPF4:1;             /*    IWPF4     */
                     unsigned char IWPF3:1;             /*    IWPF3     */
                     unsigned char IWPF2:1;             /*    IWPF2     */
                     unsigned char IWPF1:1;             /*    IWPF1     */
                     unsigned char IWPF0:1;             /*    IWPF0     */
                     }      BIT;                        /*              */
};                                                      /*              */
union un_mstcr1 {                                       /* union MSTCR1 */
                unsigned char BYTE;                     /*  Byte Access */
                struct {                                /*  Bit  Access */
                       unsigned char       :1;          /*              */
                       unsigned char MSTIIC:1;          /*    MSTIIC    */
                       unsigned char MSTS3 :1;          /*    MSTS3     */
                       unsigned char MSTAD :1;          /*    MSTAD     */
                       unsigned char MSTWD :1;          /*    MSTWD     */
                       unsigned char MSTTW :1;          /*    MSTTW     */
                       unsigned char MSTTV :1;          /*    MSTTV     */
                       unsigned char MSTTA :1;          /*    MSTTA     */
                       }      BIT;                      /*              */
};                                                      /*              */
union un_tscr {                                         /* union TSCR   */
              unsigned char BYTE;                       /*  Byte Access */
              struct {                                  /*  Bit  Access */
                     unsigned char       :6;            /*              */
                     unsigned char IICRST:1;            /*    IICRST    */
                     unsigned char IICX  :1;            /*    IICX      */
                     }      BIT;                        /*              */
};                                                      /*              */
union un_ekr {                                          /* union EKR    */
             unsigned char BYTE;                        /*  Byte Access */
             struct {                                   /*  Bit  Access */
                    unsigned char B7:1;                 /*    Bit 7     */
                    unsigned char B6:1;                 /*    Bit 6     */
                    unsigned char B5:1;                 /*    Bit 5     */
                    unsigned char B4:1;                 /*    Bit 4     */
                    unsigned char B3:1;                 /*    Bit 3     */
                    unsigned char B2:1;                 /*    Bit 2     */
                    unsigned char B1:1;                 /*    Bit 1     */
                    unsigned char B0:1;                 /*    Bit 0     */
                    }      BIT;                         /*              */
};                                                      /*              */
#define FLASH   (*(volatile struct st_flash *)0xFF90)   /* FLASH Address*/
#define TA      (*(volatile struct st_ta    *)0xFFA6)   /* TA    Address*/
#define TV      (*(volatile struct st_tv    *)0xFFA0)   /* TV    Address*/
#define TW      (*(volatile struct st_tw    *)0xFF80)   /* TW    Address*/
#define SCI3    (*(volatile struct st_sci3  *)0xFFA8)   /* SCI3  Address*/
#define AD      (*(volatile struct st_ad    *)0xFFB0)   /* A/D   Address*/
#define WDT     (*(volatile struct st_wdt   *)0xFFC0)   /* WDT   Address*/
#define IIC     (*(volatile struct st_iic   *)0xFFC4)   /* IIC   Address*/
#define ICDR    EQU.ICE1.UN_ICDR                        /* ICDR  Change */
#define ICMR    EQU.ICE1.UN_ICMR                        /* ICDR  Change */
#define SAR     EQU.ICE0.UN_SAR                         /* SAR   Change */
#define SARX    EQU.ICE0.UN_SARX                        /* SARX  Change */
#define ABRK    (*(volatile struct st_abrk  *)0xFFC8)   /* ABRK  Address*/
#define IO      (*(volatile struct st_io    *)0xFFD0)   /* IO    Address*/
#define SYSCR1  (*(volatile union  un_syscr1*)0xFFF0)   /* SYSCR1Address*/
#define SYSCR2  (*(volatile union  un_syscr2*)0xFFF1)   /* SYSCR2Address*/
#define IEGR1   (*(volatile union  un_iegr1 *)0xFFF2)   /* IEGR1 Address*/
#define IEGR2   (*(volatile union  un_iegr2 *)0xFFF3)   /* IEGR2 Address*/
#define IENR1   (*(volatile union  un_ienr1 *)0xFFF4)   /* IENR1 Address*/
#define IRR1    (*(volatile union  un_irr1  *)0xFFF6)   /* IRR1  Address*/
#define IWPR    (*(volatile union  un_iwpr  *)0xFFF8)   /* IWPR  Address*/
#define MSTCR1  (*(volatile union  un_mstcr1*)0xFFF9)   /* MSTCR1Address*/
#define TSCR    (*(volatile union  un_tscr  *)0xFFFC)   /* TSCR  Address*/
#define EKR     (*(volatile union  un_ekr   *)0xFF10)   /* EKR   Address*/

I’ve got to assume a cro is some sort of oscilloscope?

in the code clip you posted you set P0 low before P1 but called P0 CS in the comment. This is incorrect, you need to make certain CLK is low before you set CS low. You also need to release and re-assert CS between bytes. Lastly, unless I am looking at the wrong data sheet the sync byte = 0xF5 = 245, and backlight off = 0x20 = 32.
modtronix.com/products/lcd2s/lcd2sr1_v120.pdf

Try this

high P0 ; CS de-selected pause 10 low P1 ; CLK establish LOW before asserting CS low P0 ; CS asserted LOW shiftout P2,P1,msbpre,[245] ; sync command = 0xF5 = 245 high P0 ; CS de-selected pause 10 low P0 ; CS asserted LOW shiftout P2,P1,msbpre,[32] ; backlight off = 0x20 = 32 high P0 ; CS de-selected

the c code at the link you supply does the same basic thing as the basic code I provided. he implements shifting the data out a little differently. instead of shifting the output data byte and always using the MSB to set SP_OUT he uses a mask byte to select the bit to send and sets SP_OUT accordingly, then shifts the mask byte. it’s the same effect, MSB goes first. The only significant difference is how he reads the incomming byte (his is correct and reads the bit after the CLK goes L->H) but you are not using that so it is a wash.

this is a dumb question and you have probably already answered it, but are you certain both switches of the DIP switch are in the ON position? the SPI input will get ignored if they are not set.

thanks dude. not a dumb question at all. yes as far as i can tell everything is setup correctly. i always check to see if it will work in both positions.

i figured out the 0xF5 command after i had already made that post. silly me. it still doesn’t work though.

Starting Compiler…
c:\program files\basicmicro\basicatom-pro ide\lcd c style\spi.c
h8300-coff-gcc.exe: installation problem, cannot exec `cc1’: No such file or directory
Linking…
h8300-coff-gcc.exe: c:\program files\basicmicro\basicatom-pro ide\lcd c style\spi.o: No such file or directory
Errors Detected

would i right in assuming i need to install GCC? why is nothing easy with programming…

OK, did you have questions about it?

It looks reasonable on first glance. It can be tough, though, the uP clock speed can change the nop() times.

MSD out first?

The level of the SPI_OUT line between bytes can have an effect.

Alan KM6VV

klims, did you try the code I posted above and verify the correct waveforms on your scope? There is no obvious reason the BASIC code should not work, and changing compilers brings a ton of extraneous variables into play that will just make debugging the problem even more difficult. the code is straight forward enough that basic micro should be able to test it with whatever the current IDE flavor is and verify their shiftout command works or does not. :confused:

Actually the GCC compiler was installed. I think I had a thread about this (or may have been a set of private messages), but the problem with 8.0.1.0 was that it did not set the path environment variable to locate the necessary programs. I don’t have the exact paths right now as I am on a portable that does not have any of this installed on it. It is in a sub-directory that is part of the BAP installation point. You can either manually try adding this to your path environment variable or you can try installing his latest beta as I think he fixed this for about 8.0.1.2.

As for the C code, the only thing I did was to make it work with the structured register definitions and put a dummy Nop() function in. If I were doing it for myself I would probably put in a real timer function based off one of the system timers.

Also looking at the code I posted, there may need to be some more initialization code added. For example to make sure the correct ports are either input or output.

Looking at the Basic code that Eddie posted I think this should probably work as well. If I get a chance I may try to use my very limited parallax USB ossciloscope to see if it at least outputs something. This has a very very limited buffer so I may not see much, but…

For the fun of it I tried some simple shift out code on version 8.0.1.3 and tried to capture it on an older version of the parallax USB osc… software.

The code I used was:

[code]
x = “A”

low p0
low p3
main
shiftout p0, p3, msbpre, [x\8]
pause 5
goto main[/code]

What I captured was:
http://img359.imageshack.us/img359/5350/shiftoutkn9.png

The REd is the CLK signal and the blue is the data. It appears to leave the clock line low and the data line high. Not sure if that is good or not.

It appears like it is outputing the bits: 0 1 0 0 0 0 0 1
Which does coorespond to “A”.

I hope this helps.

Kurt

I read a little bit about this last night in the Atom manual and it mentioned the pins remain in same state at the end of the command high or low, which ever state it was in at the time. I don’t have the manual in front of me so I can’t say for sure.

I thought that something like that may be the case, but I did not see anything in the current electronic manual. That is why for the fun of it I put the LOW commands in at the start. They did not appear to make any difference in the levels. I wonder if he simply leaves the output pin at the last bits value. I may experiment tomorrow to see if this might be the case…

So is an Atom SPI program or a ‘C’ SPI program wanted? I missed something in the thread I guess. I have some C code working; (although it could work better) if that’s what’s wanted.

Alan KM6VV

kurke - thanks for the help. looks a lot like what i am getting. is it possible to shorten the time scale of your little device to get a better reading? i see the same thing but my cro(cathode ray oscilloscope) can’t do it.

KM6VV - i’d love to try some C code, because the Mr Modtronix tells me that the C code posted definitely works. i will need to get me a beta version of the IDE though.

EddieB - the only thing i can verify on my S&*T c.r.o is that the waveform looks correct, but i cannot get it accurate enough to check the timing. from what i can see it looks like the output is ok.

at this point the waveforms have been verified and the SHIFTOUT command does work. the only thing i put the LCD not working down to is timing.
any suggestions anyone? anything at all?

For which processor? I thought I saw PIC, then there was something else.

Alan KM6VV

I think I had the little thing running as fast as I could. I brought over the latest version of the software to the machine, but have not had a chance to try it yet.

As for C code, I did post a version of it that compiles. You might try the beta version of the IDE or you can simply search for the exe files that fail and add those manually to your path environment variable. I believe may need to add two paths to it. Sorry but it is not on this machine or I would tell you the exact strings.

Have you tried the Basic code to see if it worked? My guess is that you can be almost as slow as you want in the output routines as long as there is enough delay when the clock changes state for the LCD to sample the value.

That is all that I can think of now.

Kurt

i’ve tried all versions of basic code and nothing works. i even tried a few of my own with no luck.

as for the C code, i just installed the 8.0.1.2 and i’m still having the same problem. it comes up with the same error. was it maybe a different version that works with C?

yeah i was thinking it might be a timing thing to do with the LCD, but Modtronix claims the LCD is capable of up to 1MB/s. i even tried putting in massive delays everywhere but still no luck. i think my only hope at this stage is to get the IDE to run C.

thanks for the continued support guys,
Andrew.

PS. KM6VV - im using the Basic Atom 28 pro

Hi Andrew,

So there’s a C compiler for the IDE you’re using? is that for the H8/3664 and not the Atom 28 pro? I got confused somewhere in the thread. Are you talking to a PS2 controller, or some other part?

Anyway, you should be able to do some continuous calls to the send routine, and see it on a scope. When I worked with my routines, I used a 4 channel scope. It can also be done with just 2 channels, but it’s a little harder to see the data alignment with the clocks.

You might try the C code below. IF-THEN-ELSE constructs are used to attempt to balance the instruction time and reduce the jitter. PIC18 uP, Hightec compiler. a delay routine is used instead of the nop() your sample had.

the mask could probably used for the iteration variable, and the variable i eliminated. It also appears to shift bits out in the opposite direction then your sample routine.


/*
 * Routine to send commands and receive data from PS2 via SPI
 * Shift out (LSB first) a byte to SPI
 * and simultaneously shift in (LSB first) a byte
 *
 * Call with byte to send.
 * Returns byte read.
 *
 * 09/02/07 data changes *BEFORE* negative going clock edges
 *
 * Observed 312K clock rate, 1 uS clock pulse width
 */

unsigned char ShiftInOut(unsigned char SendChr)
    {
    unsigned char i, mask;
    unsigned char RcvChr;

    RcvChr = 0;
    SPI_CMD = 1;   

    for(i = 0, mask = 1; i < 8; i++, mask <<= 1)
        {
        if(SendChr & mask)            /* output a data bit */
            SPI_CMD = 1;
        else
            SPI_CMD = 0;

        SPI_CLK = 0;                /* generate 1 uS clock pulse */

        DelayMicrosec(DELAY);

        SPI_CLK = 1;                /* Clock the Bit */

        if(SPI_DAT)                        /* input a data bit */
              RcvChr |= mask;
        else
              RcvChr &= ~mask;        /* for balance of inst time */

        DelayMicrosec(DELAY);
        }

    SPI_CMD = 1;

    return(RcvChr);
    }

Might give you some ideas. I could actually see the data starting to come back after I got some of the timing right.

On another front, I’ve got a new sonar board to play with. I2C instead of SPI which I’m more familiar with, but I found some sample I2C code to try it out. It’s supposed to be similar to talking to a 24LC256P EEPROM chip.

Alan KM6VV

I wonder if your LCD is working properly if neither the basic code nor the shiftout worked.

If you have installed the beta 8.0.1.3 and the C compiler still does not run at all, then you might need to hack the path environment variable. On the machine that I tried compiling the C code this morning the compiler ran just fine, but earlier I did have a problem on another machine. I am not sure but it might have been the machine I run Vista on. I was able to get it to work on that machine by adding stuff to path environment variable. You might try it to see if it works for you.

What you basically have to do is to open up the System control panel (open control panel and double click on system or click on start menu, right click on system and choose properties).

Go to the advanced page and click on the environment variables button.

in either the system or user area, modify or create a variable “PATH”

Assuming a default install that matches mine, you would add something like:

C:\Program Files\BasicMicro\BasicATOM-Pro IDE\h8300-coff\bin;C:\Program Files\BasicMicro\BasicATOM-Pro IDE\h8300-coff\h8300-coff\bin

You might need to restart the program after updating this. I hope this gets you up and running with the C compiler

Good Luck