EmbeddedRelated.com
Forums
Memfault Beyond the Launch

writing SPI bit banging macros to the registers

Started by aksvan December 14, 2011
Hi,

I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below

#define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
#define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
#define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
#define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
#define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
#define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
#define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
#define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
#define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
#define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH

#define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
#define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
#define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
#define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW

#define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1

#define START_IN() BitRdPortI( PBDR, 0 ) // PB0
#define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3

Any help is greatly appreciated.

Thanking you
Anil.

I suggest using the Bit...() functions instead.
For example, here are some macros I used in my SPI bit-bang library:

#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
#define SPI_CLK() BIT( &PFDRShadow, 0 )
#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
#define SPI_DIN() BitRdPortI( PCDR, 1 )

I don't know what you mean by "...the macros are written at the
wrong address."

What is your SPI divisor value (SPI_CLK_DIVISOR)?

Steve

--- In r..., "aksvan" wrote:
>
> Hi,
>
> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below
>
> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>
> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>
> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>
> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>
> Any help is greatly appreciated.
>
> Thanking you
> Anil.
>

Hello Steve,

The code was already written by some one, I am trying to fix the error. I don't know why he chose to write the macros as I mentioned.
What I mean is writing the value to an i/o port may be wrong. For example,

WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB )  // PA2 LOW

may have to take 0xFE instead of 0xFB and PEDR instead of PADR.

My SPI divisor value is 50.
I am also thinking about bit transfer in SPI. If you want to look at this, I would like to share and get help.

Thank you.

________________________________
From: seecwriter
To: r...
Sent: Wednesday, 14 December 2011 2:25 PM
Subject: [rabbit-semi] Re: writing SPI bit banging macros to the registers

 
I suggest using the Bit...() functions instead.
For example, here are some macros I used in my SPI bit-bang library:

#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
#define SPI_CLK() BIT( &PFDRShadow, 0 )
#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
#define SPI_DIN() BitRdPortI( PCDR, 1 )

I don't know what you mean by "...the macros are written at the
wrong address."

What is your SPI divisor value (SPI_CLK_DIVISOR)?

Steve

--- In r..., "aksvan" wrote:
>
> Hi,
>
> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below
>
> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>
> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>
> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>
> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>
> Any help is greatly appreciated.
>
> Thanking you
> Anil.
>
On 12/14/2011 4:25 PM, seecwriter wrote:
> What is your SPI divisor value (SPI_CLK_DIVISOR)?
>
SPI_CLK_DIVISOR would not have any bearing on bit-banged SPI.

It is only used in the code that uses the serial ports.

--
------
Scott G. Henion, Consultant
Web site: http://SHDesigns.org
------

Doh!

--- In r..., Scott Henion wrote:
>
> On 12/14/2011 4:25 PM, seecwriter wrote:
> > What is your SPI divisor value (SPI_CLK_DIVISOR)?
> >
> SPI_CLK_DIVISOR would not have any bearing on bit-banged SPI.
>
> It is only used in the code that uses the serial ports.
>
> --
> ------
> Scott G. Henion, Consultant
> Web site: http://SHDesigns.org
> ------
>

Changing IO ports and bits seems pretty radical.
I got the impression that the program was reading
data from the ADC successfully most of the time.
If you change ports you won't read anything.

It seems to me you need to create a small program
that just reads the ADC and prints out the values it
reads. Then connect a power supply to the the ADC
channel(s) and vary the input and satisfy yourself
that you can reliably read the ADC.

>________________________________
> From: anil kumar
>To: "r..."
>Sent: Wednesday, December 14, 2011 2:26 PM
>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>Hello Steve,
>The code was already written by some one, I am trying to fix the error. I don't know why he chose to write the macros as I mentioned.
>What I mean is writing the value to an i/o port may be wrong. For example,
>
>WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB )  // PA2 LOW
>
>may have to take 0xFE instead of 0xFB and PEDR instead of PADR.
>
>My SPI divisor value is 50.
>
>I am also thinking about bit transfer in SPI. If you want to look at this, I would like to share and get help.
>Thank you.
>
>________________________________
> From: seecwriter
>To: r...
>Sent: Wednesday, 14 December 2011 2:25 PM
>Subject: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>I suggest using the Bit...() functions instead.
>For example, here are some macros I used in my SPI bit-bang library:
>
>#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
>#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
>#define SPI_CLK() BIT( &PFDRShadow, 0 )
>#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
>#define SPI_DIN() BitRdPortI( PCDR, 1 )
>
>I don't know what you mean by "...the macros are written at the
>wrong address."
>
>What is your SPI divisor value (SPI_CLK_DIVISOR)?
>
>Steve
>
>--- In r..., "aksvan" wrote:
>>
>> Hi,
>>
>> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below
>>
>> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
>> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
>> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
>> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
>> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
>> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
>> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
>> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
>> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
>> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>>
>> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
>> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
>> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
>> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>>
>> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>>
>> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
>> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>>
>> Any help is greatly appreciated.
>>
>> Thanking you
>> Anil.
>
I have a GUI that shows ADC readings which are fluctuating in 100s. The circuit board was also checked and everything is fine, so I doubt SPI bit banging. The ADC reading is done in mode 3 and the code is as follows

unsigned SPI_Do_Xfer_Mode3( char bit_cnt, unsigned val_out )
{
    // Do an SPI transfer of number of bits specified by bit_cnt.
    // Clock out val_out while clocking in the return value.
    // NOTE: val_out must be left justified in 16 bits!
    unsigned val_in;

    // init return value
    val_in = 0;

    // while there are bits left to clock...
    while( bit_cnt-- )
    {
        // set DOUT according to val_out high bit
        if( val_out & 0x8000 ) SPI_DOUT_HIGH(); else SPI_DOUT_LOW();

        // clock in the DIN bit
        SPI_CLK_LOW();

        // roll next bit into high spot
        val_out <<= 1;

        // clock out the DOUT bit
        SPI_CLK_HIGH();

        // make room for next DIN bit
        val_in <<= 1;

        // save the received DIN bit
        if( SPI_DIN() ) val_in |= 0x0001;
    }

    return( val_in );
}
Thank you Steve.
________________________________
From: Steve Trigero
To: "r..."
Sent: Thursday, 15 December 2011 1:45 PM
Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers

 
Changing IO ports and bits seems pretty radical.
I got the impression that the program was reading
data from the ADC successfully most of the time.
If you change ports you won't read anything.

It seems to me you need to create a small program
that just reads the ADC and prints out the values it
reads. Then connect a power supply to the the ADC
channel(s) and vary the input and satisfy yourself
that you can reliably read the ADC.

>________________________________
> From: anil kumar
>To: "r..."
>Sent: Wednesday, December 14, 2011 2:26 PM
>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>Hello Steve,
>The code was already written by some one, I am trying to fix the error. I don't know why he chose to write the macros as I mentioned.
>What I mean is writing the value to an i/o port may be wrong. For example,
>
>WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB )  // PA2 LOW
>
>may have to take 0xFE instead of 0xFB and PEDR instead of PADR.
>
>My SPI divisor value is 50.
>
>I am also thinking about bit transfer in SPI. If you want to look at this, I would like to share and get help.
>Thank you.
>
>________________________________
> From: seecwriter
>To: r...
>Sent: Wednesday, 14 December 2011 2:25 PM
>Subject: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>I suggest using the Bit...() functions instead.
>For example, here are some macros I used in my SPI bit-bang library:
>
>#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
>#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
>#define SPI_CLK() BIT( &PFDRShadow, 0 )
>#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
>#define SPI_DIN() BitRdPortI( PCDR, 1 )
>
>I don't know what you mean by "...the macros are written at the
>wrong address."
>
>What is your SPI divisor value (SPI_CLK_DIVISOR)?
>
>Steve
>
>--- In r..., "aksvan" wrote:
>>
>> Hi,
>>
>> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below
>>
>> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
>> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
>> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
>> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
>> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
>> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
>> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
>> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
>> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
>> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>>
>> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
>> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
>> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
>> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>>
>> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>>
>> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
>> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>>
>> Any help is greatly appreciated.
>>
>> Thanking you
>> Anil.
>>
I'm not sure anything you said changes what I suggested.
It seems to me you have to isolate the SPI functions in
a small test program so you can troubleshoot them.
Also, it could be that your SPI routines are working, but
the code is not waiting for the ADC conversion time before
trying to read the result. But a test program and a scope
will tell you that.

I don't know that this is any help, but here is what I did
in my SPI bit-bang library and it's been working for years. 
These assume the device chip select has already been asserted.
Also, you have to make sure that each I/O bit is configured 
correctly as an input or output, pull-up enabled/disabled, etc.

/*
** SPI Clock    = Port F, bit 0
** SPI Data Out = Port C, bit 0
** SPI Data In  = Port C, bit 1
*/
#define SPI_CLK_H()   BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
#define SPI_CLK_L()   BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
#define SPI_CLK()     BIT( &PFDRShadow, 0 )
#define SPI_DOUT(b)   BitWrPortI( PCDR, &PCDRShadow, b, 0 )
#define SPI_DIN()     BitRdPortI( PCDR, 1 )

/* called once at power-up */
void SPIinit()
{
  SPI_CLK_H();
  SPI_DOUT( 0 );
}

/*
**  Writes a quantity of bytes from a buffer to the 
**  SPI output port.
*/
void SPIWrite( char *DataAddress, int NbrBytes )
{
  if ( SPI_CLK() )
    while ( NbrBytes-- ) {
      SPITalkn( *DataAddress++ );
    }
  else {
    while ( NbrBytes-- ) {
      SPITalkp( *DataAddress++ );
    }
  }
}
/*
**  Reads a quantity of bytes from the SPI port and
**  saves them in a buffer.
*/
void SPIRead( char *DataAddress, int NbrBytes )
{
  if ( SPI_CLK() )
    while ( NbrBytes-- ) {
      *DataAddress++ = SPITalkn( 0 );
    }
  else {
    while ( NbrBytes-- ) {
      *DataAddress++ = SPITalkp( 0 );
    }
  }
}

/*
**  Writes one data byte, and receives one data byte 
**  over the SPI port.
*/
BYTE SPITalkn( BYTE d )
{
  BYTE rb, i;
  rb = 0; i = 0x80;
  do {
    SPI_DOUT(i & d);
    SPI_CLK_L();
    i >>= 1;
    SPI_CLK_H();
    rb = (rb << 1) | SPI_DIN();
  }
  while ( i );

  return( rb );
}  

BYTE SPITalkp( BYTE d )

{
  BYTE rb, i;
  rb = 0; i = 0x80;
  do {
    SPI_DOUT(i & d);
    SPI_CLK_H();
    i >>= 1;
    SPI_CLK_L();
    rb = (rb << 1) | SPI_DIN();
  }
  while ( i );

  return( rb );
}  
>________________________________
> From: anil kumar
>To: "r..."
>Sent: Thursday, December 15, 2011 1:37 PM
>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>I have a GUI that shows ADC readings which are fluctuating in 100s. The circuit board was also checked and everything is fine, so I doubt SPI bit banging. The ADC reading is done in mode 3 and the code is as follows
>unsigned SPI_Do_Xfer_Mode3( char bit_cnt, unsigned val_out )
>{
>    // Do an SPI transfer of number of bits specified by bit_cnt.
>    // Clock out val_out while clocking in the return value.
>    // NOTE: val_out must be left justified in 16 bits!
>
>    unsigned val_in;
>
>    // init return value
>    val_in = 0;
>
>    // while there are bits left to clock...
>   
while( bit_cnt-- )
>    {
>        // set DOUT according to val_out high bit
>        if( val_out & 0x8000 ) SPI_DOUT_HIGH(); else SPI_DOUT_LOW();
>
>        // clock in the DIN bit
>        SPI_CLK_LOW();
>
>        // roll next bit into high spot
>        val_out <<= 1;
>
>        // clock out the DOUT bit
>        SPI_CLK_HIGH();
>
>        // make room for next DIN bit
>        val_in <<= 1;
>
>        // save the received DIN bit
>        if( SPI_DIN() ) val_in |= 0x0001;
>    }
>
>    return(
val_in );
>}
>
>Thank you Steve.
>________________________________
> From: Steve Trigero
>To: "r..."
>Sent: Thursday, 15 December 2011 1:45 PM
>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>Changing IO ports and bits seems pretty radical.
>I got the impression that the program was reading
>data from the ADC successfully most of the time.
>If you change ports you won't read anything.
>It seems to me you need to create a small program
>that just reads the ADC and prints out the values it
>reads. Then connect a power supply to the the ADC
>channel(s) and vary the input and satisfy yourself
>that you can reliably read the ADC.
>
>>________________________________
>> From: anil kumar
>>To: "r..."
>>Sent: Wednesday, December 14, 2011 2:26 PM
>>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>> 
>>Hello Steve,
>>The code was already written by some one, I am trying to fix the error. I don't know why he chose to write the macros as I mentioned.
>>What I mean is writing the value to an i/o port may be wrong. For example,
>>
>>WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB )  // PA2 LOW
>>
>>may have to take 0xFE instead of 0xFB and PEDR instead of PADR.
>>
>>My SPI divisor value is 50.
>>
>>I am also thinking about bit transfer in SPI. If you want to look at this, I would like to share and get help.
>>Thank you.
>>
>>________________________________
>> From: seecwriter
>>To: r...
>>Sent: Wednesday, 14 December 2011 2:25 PM
>>Subject: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>> 
>>I suggest using the Bit...() functions instead.
>>For example, here are some macros I used in my SPI bit-bang library:
>>
>>#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
>>#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
>>#define SPI_CLK() BIT( &PFDRShadow, 0 )
>>#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
>>#define SPI_DIN() BitRdPortI( PCDR, 1 )
>>
>>I don't know what you mean by "...the macros are written at the
>>wrong address."
>>
>>What is your SPI divisor value (SPI_CLK_DIVISOR)?
>>
>>Steve
>>
>>--- In r..., "aksvan" wrote:
>>>
>>> Hi,
>>>
>>> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below
>>>
>>> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
>>> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
>>> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
>>> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
>>> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
>>> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
>>> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
>>> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
>>> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
>>> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>>>
>>> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
>>> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
>>> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
>>> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>>>
>>> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>>>
>>> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
>>> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>>>
>>> Any help is greatly appreciated.
>>>
>>> Thanking you
>>> Anil.
>>
I haven't done the SPI port in a while, but I used the SPI.LIB that is supplied in DC. That was a few years ago, and as far as I know, it still works. (Of course that was DC 8.61).

-Pete F

________________________________
From: r... [mailto:r...] On Behalf Of Steve Trigero
Sent: Thursday, December 15, 2011 6:12 PM
To: r...
Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers

I'm not sure anything you said changes what I suggested.
It seems to me you have to isolate the SPI functions in
a small test program so you can troubleshoot them.
Also, it could be that your SPI routines are working, but
the code is not waiting for the ADC conversion time before
trying to read the result. But a test program and a scope
will tell you that.

I don't know that this is any help, but here is what I did
in my SPI bit-bang library and it's been working for years.
These assume the device chip select has already been asserted.
Also, you have to make sure that each I/O bit is configured
correctly as an input or output, pull-up enabled/disabled, etc.

/*
** SPI Clock = Port F, bit 0
** SPI Data Out = Port C, bit 0
** SPI Data In = Port C, bit 1
*/
#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
#define SPI_CLK() BIT( &PFDRShadow, 0 )
#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
#define SPI_DIN() BitRdPortI( PCDR, 1 )

/* called once at power-up */
void SPIinit()
{
SPI_CLK_H();
SPI_DOUT( 0 );
}

/*
** Writes a quantity of bytes from a buffer to the
** SPI output port.
*/
void SPIWrite( char *DataAddress, int NbrBytes )
{
if ( SPI_CLK() )
while ( NbrBytes-- ) {
SPITalkn( *DataAddress++ );
}
else {
while ( NbrBytes-- ) {
SPITalkp( *DataAddress++ );
}
}
}
/*
** Reads a quantity of bytes from the SPI port and
** saves them in a buffer.
*/
void SPIRead( char *DataAddress, int NbrBytes )
{
if ( SPI_CLK() )
while ( NbrBytes-- ) {
*DataAddress++ = SPITalkn( 0 );
}
else {
while ( NbrBytes-- ) {
*DataAddress++ = SPITalkp( 0 );
}
}
}

/*
** Writes one data byte, and receives one data byte
** over the SPI port.
*/
BYTE SPITalkn( BYTE d )
{
BYTE rb, i;
rb = 0; i = 0x80;
do {
SPI_DOUT(i & d);
SPI_CLK_L();
i >>= 1;
SPI_CLK_H();
rb = (rb << 1) | SPI_DIN();
}
while ( i );

return( rb );
}

BYTE SPITalkp( BYTE d )
{
BYTE rb, i;
rb = 0; i = 0x80;
do {
SPI_DOUT(i & d);
SPI_CLK_H();
i >>= 1;
SPI_CLK_L();
rb = (rb << 1) | SPI_DIN();
}
while ( i );

return( rb );
}

________________________________
From: anil kumar
To: "r..."
Sent: Thursday, December 15, 2011 1:37 PM
Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
I have a GUI that shows ADC readings which are fluctuating in 100s. The circuit board was also checked and everything is fine, so I doubt SPI bit banging. The ADC reading is done in mode 3 and the code is as follows

unsigned SPI_Do_Xfer_Mode3( char bit_cnt, unsigned val_out )
{
// Do an SPI transfer of number of bits specified by bit_cnt.
// Clock out val_out while clocking in the return value.
// NOTE: val_out must be left justified in 16 bits!

unsigned val_in;

// init return value
val_in = 0;

// while there are bits left to clock...
while( bit_cnt-- )
{
// set DOUT according to val_out high bit
if( val_out & 0x8000 ) SPI_DOUT_HIGH(); else SPI_DOUT_LOW();

// clock in the DIN bit
SPI_CLK_LOW();

// roll next bit into high spot
val_out <<= 1;

// clock out the DOUT bit
SPI_CLK_HIGH();

// make room for next DIN bit
val_in <<= 1;

// save the received DIN bit
if( SPI_DIN() ) val_in |= 0x0001;
}

return( val_in );
}

Thank you Steve.
________________________________
From: Steve Trigero
To: "r..."
Sent: Thursday, 15 December 2011 1:45 PM
Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
Changing IO ports and bits seems pretty radical.
I got the impression that the program was reading
data from the ADC successfully most of the time.
If you change ports you won't read anything.

It seems to me you need to create a small program
that just reads the ADC and prints out the values it
reads. Then connect a power supply to the the ADC
channel(s) and vary the input and satisfy yourself
that you can reliably read the ADC.
________________________________
From: anil kumar
To: "r..."
Sent: Wednesday, December 14, 2011 2:26 PM
Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
Hello Steve,

The code was already written by some one, I am trying to fix the error. I don't know why he chose to write the macros as I mentioned.
What I mean is writing the value to an i/o port may be wrong. For example,
WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
may have to take 0xFE instead of 0xFB and PEDR instead of PADR.
My SPI divisor value is 50.

I am also thinking about bit transfer in SPI. If you want to look at this, I would like to share and get help.

Thank you.

________________________________
From: seecwriter
To: r...
Sent: Wednesday, 14 December 2011 2:25 PM
Subject: [rabbit-semi] Re: writing SPI bit banging macros to the registers
I suggest using the Bit...() functions instead.
For example, here are some macros I used in my SPI bit-bang library:

#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
#define SPI_CLK() BIT( &PFDRShadow, 0 )
#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
#define SPI_DIN() BitRdPortI( PCDR, 1 )

I don't know what you mean by "...the macros are written at the
wrong address."

What is your SPI divisor value (SPI_CLK_DIVISOR)?

Steve

--- In r..., "aksvan" wrote:
>
> Hi,
>
> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet is below
>
> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>
> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>
> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>
> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>
> Any help is greatly appreciated.
>
> Thanking you
> Anil.
>
I agree that using spi.lib would be better. But it uses a serial port
and that may not be available for this poster. 

>________________________________
> From: "Fournier, Peter"
>To: "r..."
>Sent: Friday, December 16, 2011 5:42 AM
>Subject: RE: [rabbit-semi] Re: writing SPI bit banging macros to the registers

>I haven't done the SPI port in a while, but I used the SPI.LIB that is supplied in DC.  That was a few years ago, and as far as I know, it still works. (Of course that was DC 8.61).

>-Pete F


>________________________________
> From: r... [mailto:r...] On Behalf Of Steve Trigero
>Sent: Thursday, December 15, 2011 6:12 PM
>To: r...
>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>I'm not sure anything you said changes what I suggested.
>It seems to me you have to isolate the SPI functions in
>a small test program so you can troubleshoot them.
>Also, it could be that your SPI routines are working, but
>the code is not waiting for the ADC conversion time before
>trying to read the result. But a test program and a scope
>will tell you that.
>I don't know that this is any help, but here is what I did
>in my SPI bit-bang library and it's been working for years. 
>These assume the device chip select has already been asserted.
>Also, you have to make sure that each I/O bit is configured 
>correctly as an input or output, pull-up enabled/disabled, etc.
>/*
>** SPI Clock    = Port F, bit 0
>** SPI Data Out = Port C, bit 0
>** SPI Data In  = Port C, bit 1
>*/
>#define SPI_CLK_H()   BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
>#define SPI_CLK_L()   BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
>#define SPI_CLK()     BIT( &PFDRShadow, 0 )
>#define SPI_DOUT(b)   BitWrPortI( PCDR, &PCDRShadow, b, 0 )
>#define SPI_DIN()     BitRdPortI( PCDR, 1 )
>/* called once at power-up */
>void SPIinit()
>{
>  SPI_CLK_H();
>  SPI_DOUT( 0 );
>}
>/*
>**  Writes a quantity of bytes from a buffer to the 
>**  SPI output port.
>*/
>void SPIWrite( char *DataAddress, int NbrBytes )
>{
>  if ( SPI_CLK() )
>    while ( NbrBytes-- ) {
>      SPITalkn( *DataAddress++ );
>    }
>  else {
>    while ( NbrBytes-- ) {
>      SPITalkp( *DataAddress++ );
>    }
>  }
>}
>/*
>**  Reads a quantity of bytes from the SPI port and
>**  saves them in a buffer.
>*/
>void SPIRead( char *DataAddress, int NbrBytes )
>{
>  if ( SPI_CLK() )
>    while ( NbrBytes-- ) {
>      *DataAddress++ = SPITalkn( 0 );
>    }
>  else {
>    while ( NbrBytes-- ) {
>      *DataAddress++ = SPITalkp( 0 );
>    }
>  }
>}
>/*
>**  Writes one data byte, and receives one data byte 
>**  over the SPI port.
>*/
>BYTE SPITalkn( BYTE d )
>{
>  BYTE rb, i;
>  rb = 0; i = 0x80;
>  do {
>    SPI_DOUT(i & d);
>    SPI_CLK_L();
>    i >>= 1;
>    SPI_CLK_H();
>    rb = (rb << 1) | SPI_DIN();
>  }
>  while ( i );
>  return( rb );
>}  
>BYTE SPITalkp( BYTE d )
>
>{
>  BYTE rb, i;
>  rb = 0; i = 0x80;
>  do {
>    SPI_DOUT(i & d);
>    SPI_CLK_H();
>    i >>= 1;
>    SPI_CLK_L();
>    rb = (rb << 1) | SPI_DIN();
>  }
>  while ( i );
>  return( rb );
>}  
>
>>________________________________
>> From: anil kumar
>>To: "r..."
>>Sent: Thursday, December 15, 2011 1:37 PM
>>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>> 
>>I have a GUI that shows ADC readings which are fluctuating in 100s. The circuit board was also checked and everything is fine, so I doubt SPI bit banging. The ADC reading is done in mode 3 and the code is as follows
>>unsigned SPI_Do_Xfer_Mode3( char bit_cnt, unsigned val_out )
>>{
>>    // Do an SPI transfer of number of bits specified by bit_cnt.
>>    // Clock out val_out while clocking in the return value.
>>    // NOTE: val_out must be left justified in 16 bits!
>>
>>    unsigned val_in;
>>
>>    // init return value
>>    val_in = 0;
>>
>>    // while there are bits left to clock...
>>    while( bit_cnt-- )
>>    {
>>        // set DOUT according to val_out high bit
>>        if( val_out & 0x8000 ) SPI_DOUT_HIGH(); else SPI_DOUT_LOW();
>>
>>        // clock in the DIN bit
>>        SPI_CLK_LOW();
>>
>>        // roll next bit into high spot
>>        val_out <<= 1;
>>
>>        // clock out the DOUT bit
>>        SPI_CLK_HIGH();
>>
>>        // make room for next DIN bit
>>        val_in <<= 1;
>>
>>        // save the received DIN bit
>>        if( SPI_DIN() ) val_in |= 0x0001;
>>    }
>>
>>    return( val_in );
>>}
>>
>>Thank you Steve.
>>________________________________
>> From: Steve Trigero
>>To: "r..."
>>Sent: Thursday, 15 December 2011 1:45 PM
>>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>> 
>>Changing IO ports and bits seems pretty radical.
>>I got the impression that the program was reading
>>data from the ADC successfully most of the time.
>>If you change ports you won't read anything.
>>It seems to me you need to create a small program
>>that just reads the ADC and prints out the values it
>>reads. Then connect a power supply to the the ADC
>>channel(s) and vary the input and satisfy yourself
>>that you can reliably read the ADC.
>>
>>>________________________________
>>> From: anil kumar
>>>To: "r..."
>>>Sent: Wednesday, December 14, 2011 2:26 PM
>>>Subject: Re: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>>>
>>>
>>> 
>>>Hello Steve,
>>>
>>>
>>>The code was already written by some one, I am trying to fix the error. I don't know why he chose to write the macros as I mentioned.
>>>What I mean is writing the value to an i/o port may be wrong. For example,
>>>
>>>WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB )  // PA2 LOW
>>>
>>>may have to take 0xFE instead of 0xFB and PEDR instead of PADR.
>>>
>>>My SPI divisor value is 50.
>>>
>>>
>>>
>>>I am also thinking about bit transfer in SPI. If you want to look at this, I would like to share and get help.
>>>
>>>
>>>Thank you.
>>>
>>>
>>>
>>>________________________________
>>> From: seecwriter
>>>To: r...
>>>Sent: Wednesday, 14 December 2011 2:25 PM
>>>Subject: [rabbit-semi] Re: writing SPI bit banging macros to the registers
>>>
>>>
>>> 
>>>I suggest using the Bit...() functions instead.
>>>For example, here are some macros I used in my SPI bit-bang library:
>>>
>>>#define SPI_CLK_H() BitWrPortI( PFDR, &PBDRShadow, 1, 0 )
>>>#define SPI_CLK_L() BitWrPortI( PFDR, &PBDRShadow, 0, 0 )
>>>#define SPI_CLK() BIT( &PFDRShadow, 0 )
>>>#define SPI_DOUT(b) BitWrPortI( PCDR, &PCDRShadow, b, 0 )
>>>#define SPI_DIN() BitRdPortI( PCDR, 1 )
>>>
>>>I don't know what you mean by "...the macros are written at the
>>>wrong address."
>>>
>>>What is your SPI divisor value (SPI_CLK_DIVISOR)?
>>>
>>>Steve
>>>
>>>--- In r..., "aksvan" wrote:
>>>>
>>>> Hi,
>>>>
>>>> I am new to this software. I am using rabbit 4010 with dynamic C 10.56 version. The SPI code is written for rabbit, ADC chip (LTC1400)and ADC, MUX (LTC1391).I have a question regarding SPI bit banging macros. According to my application, it should control
the pressure but there is an unknown error in the software that is causing the fluctuation in the pressure. I think the macros are written at wrong addresses. I tried to check if they are correct but I could not find this in any documents. The code snippet
is below
>>>>
>>>> #define CS_CONV_HIGH() WrPortI( PEDR, &PEDRShadow, PEDRShadow | 0x08 ) // PE3 HIGH
>>>> #define CS_CONV_LOW() WrPortI( PEDR, &PEDRShadow, PEDRShadow & 0xF7 ) // PE3 LOW
>>>> #define CS_MUX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x04 ) // PA2 HIGH
>>>> #define CS_MUX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0xFB ) // PA2 LOW
>>>> #define CS_PEX_ON() WrPortI( PADR, &PADRShadow, PADRShadow | 0x80 ) // PA7 HIGH
>>>> #define CS_PEX_OFF() WrPortI( PADR, &PADRShadow, PADRShadow & 0x7F ) // PA7 LOW
>>>> #define CS_PELTIER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xEF ) // PA4 LOW
>>>> #define CS_PELTIER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x10 ) // PA4 HIGH
>>>> #define CS_HEATER_DAC_ON() WrPortI( PADR, &PADRShadow, PADRShadow & 0xF7 ) // PA3 LOW
>>>> #define CS_HEATER_DAC_OFF() WrPortI( PADR, &PADRShadow, PADRShadow | 0x08 ) // PA3 HIGH
>>>>
>>>> #define SPI_CLK_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x08 ) // PC3 HIGH
>>>> #define SPI_CLK_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xF7 ) // PC3 LOW
>>>> #define SPI_DOUT_HIGH() WrPortI( PCDR, &PCDRShadow, PCDRShadow | 0x01 ) // PC0 HIGH
>>>> #define SPI_DOUT_LOW() WrPortI( PCDR, &PCDRShadow, PCDRShadow & 0xFE ) // PC0 LOW
>>>>
>>>> #define SPI_DIN() BitRdPortI( PCDR, 1 ) // PC1
>>>>
>>>> #define START_IN() BitRdPortI( PBDR, 0 ) // PB0
>>>> #define STOP_IN() BitRdPortI( PBDR, 3 ) // PB3
>>>>
>>>> Any help is greatly appreciated.
>>>>
>>>> Thanking you
>>>> Anil.
>>>>
>>>
>>>
>>>
>>>
>>>
>>

Memfault Beyond the Launch