Pages: 1 2 [3]   Go Down
Author Topic: Reading MOSI data from Bosch ASIC  (Read 2995 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 480
Posts: 18719
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I see no point in it, as the whole byte has to sent over serial regardless...

You've lost me there. Do you want to send a whole lot of zeroes? If you are sending the raw data, the single byte is sent anyway. The leading zeroes are just how it is displayed.
Logged


UK
Offline Offline
God Member
*****
Karma: 1
Posts: 530
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For a value of 0, I can completely understand why one wouldn't write 00000000, but for 1100011 - it seems strange to me to omit the leading 0.

I suppose just my inexperience with this sort of thing in general, still - I'm glad I've got it working. I'll take a look on a logic analyser in the next few days, and see if the data is sent back simultaneously with those dummy bits, or after those dummy bits. I'd be interested to know.

EDIT - I suppose if my first encounters with this had been on a 32bit architecture for example, it would make more sense to me to not be printing 00000000000000000000000000000001 for example! (feel free to double check the 31 leading 0s, I can't say I checked myself!)
« Last Edit: January 30, 2013, 05:32:14 pm by jtw11 » Logged

California
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guys :

sorry ... i'm late ...

since i'm currently involved in an avr (poor avr) and a cj125, please allow me a few comments to the cj125 and the code found in the previous posts

i will include code or make more available upon request ... so don't jump on my "i would not"

i would not use floats on a humble 8-bit cpu
i would not use the built in spi functions
i would not use println, since printf was invented

no com err check on rd or wr to the cj125

you can not run pid and expect the I-err-term being correct if you don't assure that the sampling and err-term calculations are done on a fixed period ... you assume that your main loop execution is always at the same loop cycle run-time basis
http://www.embedded.com/design/embedded/4211211/PID-without-a-PhD

yes ... this c++ code runs in the arduino ide

it is currently used to read the cj125 diag_reg with adr=0x78 and dat=0x00

it checks for the return of xx101xxx and if correct clocks the 2nd "dat" out and receives efiSpi.Dat and efiSpi.Adr

i would have more suggestions and some questions if anyone working with the cj125 is interested

i realize that it doesn't need to be in a class, but i like it this way

Code:
//---------------------------------------------------------------------------
#ifndef efiSpiH
#define efiSpiH
//---------------------------------------------------------------------------

class  TSpi ;
extern TSpi efiSpi ;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

class  TSpi
{
public :

  enum { eRevSpi = 0x13030900 } ;

  static const DWORD cRevNum ;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - -

private :

public :

  BYTE  Adr, Dat ;

  bool Com(BYTE adr, BYTE dat) ;

} ;

//---------------------------------------------------------------------------
#endif /* efiSpiH */


and here the .cpp ...

i like to have a simple revision indicator in every module like ...

const DWORD TSpi::cRevNum = { eRevSpi } ;

Type.h contains all the

typedef       unsigned short   int    WORD ;

Code:
#include <Arduino.h>

#include   "Type.h"
#include "efiSpi.h"

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#define cCS   0x01
#define cMOSI 0x08
#define cMISO 0x10
#define cSCK  0x20

#define NOP __asm__ __volatile__ ("nop\n\t")

//---------------------------------------------------------------------------

TSpi efiSpi ;

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

const DWORD TSpi::cRevNum = { eRevSpi } ;

//---------------------------------------------------------------------------

bool TSpi::Com(BYTE adr, BYTE dat)
{
  bool ret = true ;     
       
/* noInterrupts() ; not working */
 
  PORTB &= ~cSCK ; /* 1st */
  NOP ; /* 2nd.0 */
  NOP ; /* 2nd.1 */
  NOP ; /* 2nd.2 */
  NOP ; /* 2nd.3 */
  NOP ; /* 2nd.4 */
  NOP ; /* 2nd.5 */
  NOP ; /* 2nd.6 */
  PORTB &= ~cCS ; /* 3rd */
  NOP ; /* space */

  for (BYTE i = 8 ; i-- ; ) { /* adr, MSB-First */

    PORTB |=  cSCK ;

    if (adr & 0x80) PORTB |=  cMOSI ;
    else     PORTB &= ~cMOSI ;

    adr <<= 1 ;

    PORTB &= ~cSCK ;

    NOP ;
    NOP ;

    if (PINB & cMISO) adr |=  1 ;
    else       adr &= ~1 ;

  }     Adr = adr ;

  if ((adr &= 0x38) == 0x28) { /* adr == xx101xxx */

    for (BYTE i = 8 ; i-- ; ) { /* dat, MSB-First */

      PORTB |=  cSCK ;

      if (dat & 0x80) PORTB |=  cMOSI ;
      else       PORTB &= ~cMOSI ;

      dat <<= 1 ;

      PORTB &= ~cSCK ;

      NOP ;
      NOP ;

      if (PINB & cMISO) dat |=  1 ;
      else dat &= ~1 ;

    }     Dat = dat ;
  } else {  Dat = 0 ;  ret = false ; }         
 
  NOP ; /* space */
  PORTB |=  cCS ; /* 1st */
  NOP ; /* 2nd.0 */
  NOP ; /* 2nd.1 */
  NOP ; /* 2nd.2 */
  NOP ; /* 2nd.3 */
  NOP ; /* 2nd.4 */
  NOP ; /* 2nd.5 */
  NOP ; /* 2nd.6 */
  PORTB |=  cSCK ; /* 3nd */

/* interrupts() ; not working */

  return ret ;
}
//---------------------------------------------------------------------------

while the cj125 is a sweet chip and now available, the correct application of the "pump current reference" in the "bosch diagram box 12"  for the lsu 4.9 sensor only is for me unknown at this time, as well as the settings in the wr_init2 register

cheers, blue2u
Logged

Pages: 1 2 [3]   Go Up
Jump to: