hi guys :
there was a previous post about using the Bosch CJ125 Asic
it was old (jan) and long and i do not want to add at the bottom, so i start a new one
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 post "Reading MOSI data from Bosch ASIC"
the included code contains a 16-bit bit-banged SPI implementation specifically tailored for the cj125
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
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
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
//---------------------------------------------------------------------------
#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 ;
#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