示例#1
0
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
{
  int mask, old, reg ;

  pin -= node->pinBase ;

  if (pin < 8)		// Bank A
    reg  = MCP23x17_GPPUA ;
  else
  {
    reg  = MCP23x17_GPPUB ;
    pin &= 0x07 ;
  }

  mask = 1 << pin ;
  old  = wiringPiI2CReadReg8 (node->fd, reg) ;

  if (mode == PUD_UP)
    old |=   mask ;
  else
    old &= (~mask) ;

  wiringPiI2CWriteReg8 (node->fd, reg, old) ;
}
static int32_t _readRawPressure(struct bmp_t *bmp)
{
  #if BMP085_USE_DATASHEET_VALS
    return 23843;
  #else
    uint8_t  p8;
    uint16_t p16;
    int32_t  p32;

    wiringPiI2CWriteReg8(bmp->fd,BMP085_REGISTER_CONTROL, BMP085_REGISTER_READPRESSURECMD + (_bmp085Mode << 6));
    switch(_bmp085Mode)
    {
      case BMP085_MODE_ULTRALOWPOWER:
        usleep(5000);
        break;
      case BMP085_MODE_STANDARD:
        usleep(8000);
        break;
      case BMP085_MODE_HIGHRES:
        usleep(14000);
        break;
      case BMP085_MODE_ULTRAHIGHRES:
      default:
        usleep(26000);
        break;
    }

    p16 = (uint16_t)_readReg16BigEndian(bmp->fd,BMP085_REGISTER_PRESSUREDATA);
    p32 = (uint32_t)p16 << 8;
    p8 = (uint8_t)wiringPiI2CReadReg8(bmp->fd,BMP085_REGISTER_PRESSUREDATA+2);
    p32 += p8;
    p32 >>= (8 - _bmp085Mode);
    
    return p32;
  #endif
}
int checkOneDigipot(char *digipot_label) // for chip tests only
{
	int wiper_value = -1 ;
	
	struct digipot *digipot = digipots ;	
	for (; digipot < digipots + numberofdigipots ; digipot++)
	{
		int found = 0 ;
		int loop = 0 ;
		for (; loop < digipot->digipot_channels ; loop++)
		{
			if (digipot_label == digipot->digipot_label[loop])
			{
				if (digipot->digipot_reference == "AD5263") // chip from Analog Device
				{
					int slaveAddressByte = digipot->digipot_address << 1 | 0b0 ; // prepare the first byte including the internal sub digipot address, only for displaying and tests, because it's sent automaticaly by wiringpi itself, don't care !	
					int instructionByte = loop << 5 ; // this is the "int reg", the second I2C byte sent by wiringpi
					printf("\n * checking values of DIGIPOT:[%d]: \"%s\" \n", loop, digipot->digipot_label[loop]) ;
					
					wiper_value = 0 ;
					for (; wiper_value < 256 ; wiper_value++)
					{
						wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, wiper_value) ; // send the complete I2C frame to the chip
						if (wiper_value == 0) { delay(1500) ; } else { delay(10) ; } // let the time to any mechanical galvanometer to reset for low values measurement
					}
					printf("-- done --\n\n") ;
				}
				
				found = 1 ;
				break ;	
			}
		}
		if (found == 1) { break ; }
	}
	return wiper_value ;
}
// Connect to the device on I2C and ensure it exists
int Gyroscope_ITG3200::ConnectToI2C(int address)
{
	// Setup the WiringPi I2C library and connect to the motor controller
	m_WiringPi_I2C = wiringPiI2CSetup(address);
	if (m_WiringPi_I2C == -1)
	{
		if (DEBUG_MODE)
			printf("Gyroscope_ITG3200 - wiringPi setup failed\n");

		return -1;
	}

	if (DEBUG_MODE)
		printf("Gyroscope_ITG3200 - wiringPi connected to sensor\n");

	// Set full scale range, highest sampling
	wiringPiI2CWriteReg8(m_WiringPi_I2C, REG_DLPF_FS, 0x18);


	// Wait to turn on
	delay(50);

	return 1;
}
示例#5
0
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
{
  int mask, old, reg ;

  pin -= node->pinBase ;

  if (pin < 8)		// Bank A
    reg  = MCP23x17_IODIRA ;
  else
  {
    reg  = MCP23x17_IODIRB ;
    pin &= 0x07 ;
  }

  mask = 1 << pin ;
  old  = wiringPiI2CReadReg8 (node->fd, reg) ;

  if (mode == OUTPUT)
    old &= (~mask) ;
  else
    old |=   mask ;

  wiringPiI2CWriteReg8 (node->fd, reg, old) ;
}
示例#6
0
void adxl345_init(int fd)
{
	wiringPiI2CWriteReg8(fd, 0x31, 0x0b);
	wiringPiI2CWriteReg8(fd, 0x2d, 0x08);
	// wiringPiI2CWriteReg8(fd, 0x2e, 0x00);
	wiringPiI2CWriteReg8(fd, 0x1e, 0x00);
	wiringPiI2CWriteReg8(fd, 0x1f, 0x00);
	wiringPiI2CWriteReg8(fd, 0x20, 0x00);

	wiringPiI2CWriteReg8(fd, 0x21, 0x00);
	wiringPiI2CWriteReg8(fd, 0x22, 0x00);
	wiringPiI2CWriteReg8(fd, 0x23, 0x00);
	wiringPiI2CWriteReg8(fd, 0x24, 0x01);
	wiringPiI2CWriteReg8(fd, 0x25, 0x0f);
	wiringPiI2CWriteReg8(fd, 0x26, 0x2b);
	wiringPiI2CWriteReg8(fd, 0x27, 0x00);

	wiringPiI2CWriteReg8(fd, 0x28, 0x09);
	wiringPiI2CWriteReg8(fd, 0x29, 0xff);
	wiringPiI2CWriteReg8(fd, 0x2a, 0x80);
	wiringPiI2CWriteReg8(fd, 0x2c, 0x0a);
	wiringPiI2CWriteReg8(fd, 0x2f, 0x00);
	wiringPiI2CWriteReg8(fd, 0x38, 0x9f);
}
示例#7
0
int init_zyncoder() {
	int i,j;
	for (i=0;i<MAX_NUM_ZYNSWITCHES;i++) {
		zynswitches[i].enabled=0;
		zynswitches[i].midi_cc=0;
	}
	for (i=0;i<MAX_NUM_ZYNCODERS;i++) {
		zyncoders[i].enabled=0;
		for (j=0;j<ZYNCODER_TICKS_PER_RETENT;j++) zyncoders[i].dtus[j]=0;
	}
	wiringPiSetup();

#ifdef MCP23017_ENCODERS
	uint8_t reg;

	mcp23017Setup(MCP23017_BASE_PIN, 0x20);

	// get the node cooresponding to our mcp23017 so we can do direct writes
	mcp23017_node = wiringPiFindNode(MCP23017_BASE_PIN);

	// setup all the pins on the banks as inputs and disable pullups on
	// the zyncoder input
	reg = 0xff;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IODIRA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IODIRB, reg);

	// enable pullups on the unused pins (high two bits on each bank)
	reg = 0xff;
	//reg = 0xc0;
	//reg = 0x60;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPPUA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPPUB, reg);

	// disable polarity inversion
	reg = 0;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IPOLA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IPOLB, reg);

	// disable the comparison to DEFVAL register
	reg = 0;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_INTCONA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_INTCONB, reg);

	// configure the interrupt behavior for bank A
	uint8_t ioconf_value = wiringPiI2CReadReg8(mcp23017_node->fd, MCP23x17_IOCON);
	bitWrite(ioconf_value, 6, 0);	// banks are not mirrored
	bitWrite(ioconf_value, 2, 0);	// interrupt pin is not floating
	bitWrite(ioconf_value, 1, 1);	// interrupt is signaled by high
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IOCON, ioconf_value);

	// configure the interrupt behavior for bank B
	ioconf_value = wiringPiI2CReadReg8(mcp23017_node->fd, MCP23x17_IOCONB);
	bitWrite(ioconf_value, 6, 0);	// banks are not mirrored
	bitWrite(ioconf_value, 2, 0);	// interrupt pin is not floating
	bitWrite(ioconf_value, 1, 1);	// interrupt is signaled by high
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_IOCONB, ioconf_value);

	// finally, enable the interrupt pins for banks a and b
	// enable interrupts on all pins
	reg = 0xff;
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPINTENA, reg);
	wiringPiI2CWriteReg8(mcp23017_node->fd, MCP23x17_GPINTENB, reg);

	// pi ISRs for the 23017
	// bank A
	wiringPiISR(MCP23017_INTA_PIN, INT_EDGE_RISING, mcp23017_bank_ISRs[0]);
	// bank B
	wiringPiISR(MCP23017_INTB_PIN, INT_EDGE_RISING, mcp23017_bank_ISRs[1]);

#ifdef DEBUG
	printf("MCP23017 initialized: INTA %d, INTB %d\n",MCP23017_INTA_PIN,MCP23017_INTB_PIN);
#endif
#else
	mcp23008Setup (100, 0x20);
	init_poll_zynswitches();
#endif
	return 1;
}
示例#8
0
void ADXL345::enableMeasurement()
{
  wiringPiI2CWriteReg8(FD_ADDR,POWER_CTL,MEASURE);
}
示例#9
0
uint8_t u8g_i2c_send_byte(uint8_t data) {
    wiringPiI2CWriteReg8(fd, i2cMode, data);

    return 1;
}
示例#10
0
int cPwmBoard::setPwm(int reg, float duty)
{
    int val = (40.96 * duty)-1;  //0~4095 values in PWM
    int high = val>>8;    //High nibble(4bit)
    int low = val-(high<<8);      //Low byte

    #ifdef PWM_DEBUG
    std::cout<<"PWM | Writing to "<<std::hex<<reg<<" with value "<<std::hex<<high<<"|"<<std::hex<<low<<std::dec<<std::endl;
    #endif

    #ifdef LOGGING_FULL
    logfile << "PWM | Writing to " << std::hex<<reg << " with value " << std::hex<<high << "|" << std::hex<<low << std::dec << std::endl;
    #endif

    if(pwmFd == -1)
    {
        #ifdef PWM_DEBUG
        std::cout <<  "PWM | Attempted to write to non-initalised PWM board" << std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | Attempted to write to non-initalised PWM board" << std::endl;
        #endif

        return -1;
    }
    piLock(0);
    if(wiringPiI2CWriteReg8(pwmFd,reg,0)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | PWM write failed ("<<std::hex<< reg <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex<<reg <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    if(wiringPiI2CWriteReg8(pwmFd,reg+1,0)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | PWM write failed ("<<std::hex<< reg+1 <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex<<reg+1 <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    if(wiringPiI2CWriteReg8(pwmFd,reg+2,low)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | PWM write failed ("<<std::hex<< reg+2 <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex<<reg+2 <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    if(wiringPiI2CWriteReg8(pwmFd,reg+3,high)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | PWM write failed ("<<std::hex<< reg+3 <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex<<reg+3 <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    piUnlock(0);
    return 0;
}
示例#11
0
int cPwmBoard::kill(int reg)
{
    #ifdef PWM_DEBUG
	std::cout << "PWM | Killing " << std::hex << reg << std::dec << std::endl;
    #endif

    #ifdef LOGGING_FULL
    logfile << "PWM | Inverted PWM write failed (" << std::hex<<reg+3 <<std::dec << ")" << std::endl;
    #endif

	if (pwmFd == -1)
	{
        #ifdef PWM_DEBUG
		std::cout << "PWM | Attempted to write to non-initalised PWM board" << std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | Attempted to write to non-initalised PWM board" << std::endl;
        #endif

		return -1;
	}
    piLock(0);
	if (wiringPiI2CWriteReg8(pwmFd, reg, 0)<0)
	{
        #ifdef PWM_DEBUG
		std::cout << "PWM | PWM write failed (" << std::hex << reg << std::dec << ")" << std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex << reg << std::dec << ")" << std::endl;
        #endif

		return -1;
	}
	if (wiringPiI2CWriteReg8(pwmFd, reg + 1, 0)<0)
	{
        #ifdef PWM_DEBUG
		std::cout << "PWM | PWM write failed (" << std::hex << reg + 1 << std::dec << ")" << std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex << reg + 1 << std::dec << ")" << std::endl;
        #endif

		return -1;
	}
	if (wiringPiI2CWriteReg8(pwmFd, reg + 2, 0)<0)
	{
        #ifdef PWM_DEBUG
		std::cout << "PWM | PWM write failed (" << std::hex << reg + 2 << std::dec << ")" << std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex << reg + 2 << std::dec << ")" << std::endl;
        #endif

		return -1;
	}
	if (wiringPiI2CWriteReg8(pwmFd, reg + 3, 0x10)<0)
	{
        #ifdef PWM_DEBUG
		std::cout << "PWM | PWM write failed (" << std::hex << reg + 3 << std::dec << ")" << std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | PWM write failed (" << std::hex << reg + 3 << std::dec << ")" << std::endl;
        #endif

		return -1;
	}
    piUnlock(0);
	return 0;
}
示例#12
0
文件: main.c 项目: warshall/Raspi
int main (void) // Fonction principale
{
  int Ht16k, Mcp, EtatLed, EtatBTN ; // Declaration des variables.
  int i = 1 ;
  pthread_t Thread_Jeux;
  
  Ht16k = wiringPiI2CSetup (0x70) ;

 if ((Mcp = wiringPiI2CSetup (0x20)) == -1)
 {
   fprintf (stderr, "Mcp: impossible d'initialiser l'I2C: %s\n", strerror (errno)) ; return 1 ; // Si impossible a initialiser.
 }

 
  wiringPiI2CWriteReg8 (Mcp, IODIR, 0xC0) ; // Toutes les broches en OUTPUT sauf broches 6 et 7 en input.
  wiringPiI2CWriteReg8 (Mcp, GPIO, LEDNOT) ; // Eteindre toutes les LEDs
  wiringPiI2CWrite (Ht16k, 0x21) ;
  wiringPiI2CWrite (Ht16k, 0x81) ;
  Afficher (Ht16k, 0) ;

  EtatLed = LEDNOT ; // Par defaut les LEDs sont eteintes.

  struct arg_jeux TypeDeJeu = {Mcp, 0, &EtatLed, Ht16k} ;
  
 for (;;)
 {
   debut: //Etiquette goto je ne sai pas faire autrement..
   wiringPiI2CWrite (Ht16k, 0x81) ;
   EtatBTN = (wiringPiI2CReadReg8 (Mcp, GPIO) - EtatLed) ;

   if (EtatBTN == BTNG) // Si bouton gauche presser alors...
   {
     delay (200); // On attend 10ms puis on fait une relecture pour etre sur que ce n'est pas un parasite
       if ((wiringPiI2CReadReg8 (Mcp, GPIO) - EtatLed) == BTNG) // Si bouton gauche presser..
       {
         wiringPiI2CWrite (Ht16k, 0x83);
         BtnAppuiLong (Mcp, &EtatLed) ;

          while ((wiringPiI2CReadReg8 (Mcp, GPIO) - EtatLed) != BTND)
           {
             delay (20) ;

			 if ((wiringPiI2CReadReg8 (Mcp, GPIO) - EtatLed) == BTNG)
             {
               Afficher (Ht16k, i) ;
               i++ ;
                if (i == 10) {i =0 ;}
                BtnAppuiLong (Mcp, &EtatLed) ;
				TypeDeJeu.J = (i-1) ;
				TypeDeJeu.EtatLed = &EtatLed ;
				}

           }

	    pthread_cancel(Thread_Jeux);	
		pthread_create (&Thread_Jeux, NULL, Jeux, &TypeDeJeu);
        printf("coucou\n") ;

       }
   }
  delay (100); // Vitesse de la boucle
 }
return 0 ;
}
示例#13
0
/** Set magnetic field gain value.
* @param gain New magnetic field gain value
* @see getGain()
* @see HMC5883L_RA_CONFIG_B
* @see HMC5883L_CRB_GAIN_BIT
* @see HMC5883L_CRB_GAIN_LENGTH
*/
void HMC5883L::setGain(uint8_t gain) {
// use this method to guarantee that bits 4-0 are set to zero, which is a
// requirement specified in the datasheet; it's actually more efficient than
// using the I2Cdev.writeBits method
	wiringPiI2CWriteReg8(devAddr, HMC5883L_RA_CONFIG_B, gain << (HMC5883L_CRB_GAIN_BIT - HMC5883L_CRB_GAIN_LENGTH + 1));
}
void startReading(void) {
    wiringPiI2CWriteReg8(i2c, 0x80, 0x03);
}
int updateOneDigipot(char *digipot_label, int wiper_value)
{
	struct digipot *digipot = digipots ;	
	for (; digipot < digipots + numberofdigipots ; digipot++) // check the different digipots
	{
		int slaveAddressByte ;
		int instructionByte ;
		float ratio ;
		float dB ;
		struct digipot *current_digipot = digipots ; // to store what is the current digipot
		int found = 0 ;
		int digipot_switch ;
		
		int loop = 0 ;		
		for (; loop < digipot->digipot_channels ; loop++) // check the different channels
		{
			if (digipot_label == digipot->digipot_label[loop]) // it's the correct digipot target
			{

				int current_loop = loop ;
				int tap = -(wiper_value - digipot->wiper_positions) ;
				current_digipot = digipot ; // digipot target memorisation
				
				found = 1 ; // found the correct digipot target
			
				// prepare the first (slaveAddressByte) and second (instructionByte) bytes before sending a complete I2C frame
				if ((digipot->digipot_reference == "AD5263") && (digipot->digipot_group_qty == 0)) // chip from Analog Device, an I2C/SPI selectable quad_digipot accepting 15V signals
				{
					slaveAddressByte = digipot->digipot_address << 1 | 0b0 ; // prepare the first byte including the internal sub digipot address, only for displaying and tests, because it's sent automaticaly by wiringpi itself, don't care !	
					instructionByte = loop << 5 ; // this is the "int reg", the second I2C byte sent by wiringpi, selecting the correct internal digipot wiper
				}	
				else if (digipot->digipot_group_qty != 0)
				{
					// this is a SUPERDIGIPOT, a group of several real digipots but stacked in serial or parallel and drived simultaneously with a single command
					char *digipot_single_name ;
					
					loop = 0 ;					
					for (; loop < digipot->digipot_group_qty ; loop++) // scan each real digipot included in the SUPERDIGIPOT stack
					{	
						int done = 0 ;
						digipot_single_name = digipot->digipot_single_name[loop] ; // memorise the real digipot name for this loop step
						//printf("\n §§§ debut boucle FOR - loop:%d - digipot_group_qty:%d - digipot_single_name:%s - digipot->digipot_single_name:%s -", loop, digipot->digipot_group_qty, digipot_single_name, digipot->digipot_single_name[loop]) ;
						
						if (digipot->digipot_group_type == "SERIAL")
						{	
							printf("\nSERIAL\n") ;	
							if (wiper_value < (digipot->wiper_positions / digipot->digipot_group_qty) * (loop+1)) // select the only real digipot to adjust (filtering)
							{
								digipot_switch = digipot->digipot_switch[loop] ; // the correct switch ID number for the wiper is stored in memory
								//printf("\n test_if<%d - switch:%d - loop:%d - ", (digipot->wiper_positions / digipot->digipot_group_qty) * (loop+1), digipot_switch, loop) ;
	
								digipot = digipots ; // the first one digipot address in the structure in memory
								for (; digipot < digipots + numberofdigipots ; digipot++) // search the only one real digipot chip to adjust now and included in this SUPERDIGIPOT stack 
								{	
									int loop = 0 ;
									for (; loop < digipot->digipot_channels ; loop++) // search each internal digipot (channel)
									{	
										if (digipot_single_name == digipot->digipot_label[loop]) // found the correct chip channel
										{
											slaveAddressByte = digipot->digipot_address << 1 | 0b0 ; // prepare the first byte including the internal sub digipot address, only for displaying and tests, because it's sent automaticaly by wiringpi itself, don't care !	
											instructionByte = loop << 5 ; // this is the "int reg", the second I2C byte sent by wiringpi
											
											if (((wiper_value - (loop * digipot->wiper_positions)) >= 0) && ((wiper_value - (loop * digipot->wiper_positions)) < digipot->wiper_positions)) // if value in the correct and expected range
											{
												wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, wiper_value - (loop * digipot->wiper_positions)) ; // send the complete I2C frame to the chip
												digipot->digipot_value[loop] = wiper_value - (loop * digipot->wiper_positions) ; // store the wiper value in memory
												done = 1 ;
											}
										}
									}
								}
							}
						}
						else if (digipot->digipot_group_type == "PARALLEL")
						{
							digipot = digipots ; // point to the first one digipot address (beginning of the structure) in memory
							for (; digipot < digipots + numberofdigipots ; digipot++) // scan all the digipots one after other
							{	
								int loop2 = 0 ;
								for (; loop2 < digipot->digipot_channels ; loop2++) // search each internal digipot (channel) of each chip
								{	
									if (digipot_single_name == digipot->digipot_label[loop2]) // found the correct chip channel
									{	
										slaveAddressByte = digipot->digipot_address << 1 | 0b0 ; // prepare the first byte including the internal sub digipot address, only for displaying and tests, because it's sent automaticaly by wiringpi itself, don't care !	
										instructionByte = loop << 5 ; // this is the "int reg", the second I2C byte sent by wiringpi

										wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, wiper_value) ; // send the complete I2C frame to the chip
										digipot->digipot_value[loop] = wiper_value ; // store the wiper value in memory
										done = 1 ;
									}
								}
							}
							digipot = current_digipot ;
						}
					}
				}

				digipot = current_digipot ; // reload the original first digipot target
				loop = current_loop ; // reload the original first digipot loop level

				// convert digipot tap position to attenuation in dB
				if (digipot->digipot_0_position[loop] == "RIGHT")
				{
					//ratio = (float) (digipot->wiper_positions - tap) / (digipot->wiper_positions -1) ;
					ratio = (float) (digipot->wiper_positions + (digipot->wiper_positions * (digipot->digipot_ground_resistance[loop] / digipot->digipot_ohms)) - tap) / (digipot->wiper_positions + (digipot->wiper_positions * (digipot->digipot_ground_resistance[loop] / digipot->digipot_ohms)) -1) ;
					digipot->digipot_value[loop] = wiper_value ; // store the wiper value in memory
					if (digipot->digipot_group_qty == 0) { wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, wiper_value) ; } // send the complete I2C frame to the chip which is a single real digipot
				}
				else if (digipot->digipot_0_position[loop] == "CENTER")
				{
					if (wiper_value >= 0)
					{
						ratio = (float) (wiper_value + digipot->wiper_positions/2) / (digipot->wiper_positions/2) ;
						digipot->digipot_value[loop] = wiper_value + (digipot->wiper_positions / 2) - 1 ; // store the wiper value in memory
						if (digipot->digipot_group_qty == 0) { wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, wiper_value + (digipot->wiper_positions / 2) - 1) ; } // send the complete I2C frame to the chip
					}
					else
					{
						ratio = (float) (digipot->wiper_positions/2) / (digipot->wiper_positions/2 - wiper_value) ;
						digipot->digipot_value[loop] = wiper_value + (digipot->wiper_positions / 2) - 1 ; // store the wiper value in memory
						if (digipot->digipot_group_qty == 0) { wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, wiper_value + (digipot->wiper_positions / 2) - 1) ; } // send the complete I2C frame to the chip
					}	
				}
				else
				{
					printf("\n!!! ZERO position value not recognized !!!\n") ;
					printf("ELSE-digipot->digipot_0_position:%s",digipot->digipot_0_position[loop]) ;
				}
				
				if ((digipot->digipot_group_qty != 0) && (digipot->digipot_group_type == "SERIAL"))
				{
					int loop2 = 0 ;
					for (; loop2 < digipot->digipot_group_qty ; loop2++) // search each internal digipot (channel) 
					{
						if (digipot->digipot_switch[loop2] != digipot_switch) // if not the selected digipot's wipper
						{
							digitalWrite(digipot->digipot_switch[loop2], OFF) ; // switch OFF all the non-used wipers
						}
					}
					digitalWrite(digipot_switch, ON) ; // switch ON the digital output which drives the switch to select the correct
					                                   // wiper, just after have switched off all the others (never ON twice switches
					                                   // in same time, silence is better than a big noise !)
				}

				// write value to digipot chip and convert digipot tap position to attenuation in dB			
				dB = (20 * log10(ratio)) ;
				digipot->digipot_att[loop] = dB ; // store the digipot attenuation in dB
				
				if (found) { break ; } // digipot found, stop searching
			}	
			if (found) { break ; } // digipot found, stop searching
		}	
		if (found) { break ; } // digipot found, stop searching
	}
			
	return wiper_value ;
}
double digipotRead(char *digipot_label)
{
	double x = -1 ;
	struct digipot *digipot = digipots ;	
	for (; digipot < digipots + numberofdigipots ; digipot++)
	{
		int loop = 0 ;
		int found = 0 ;
		for (; loop < digipot->digipot_channels ; loop++)
		{
			int loop = 0 ; 
			if (digipot_label == digipot->digipot_label[loop])
			{
				if (digipot->digipot_group_qty == 0) // standard alone digipot
				{
	//				printf("*** digipot_label: %s - digipot->digipot_label: %d - loop: %d \n", digipot_label, digipot->digipot_label, loop) ;
					int slaveAddressByte = digipot->digipot_address << 1 | 0b0 ; // prepare the first byte including the internal sub digipot address, only for displaying and tests, because it's sent automaticaly by wiringpi itself, don't care !
					int instructionByte = loop << 5 ; // this is the "int reg", the second I2C byte sent by wiringpi
					wiringPiI2CWriteReg8(digipot->digipot_setUpIO, instructionByte, digipot->digipot_value[loop]) ; // send the complete I2C frame to the chip, rewrite the current wipper value, because the READ instruction get the last writed digipot
					
					int x = -1 ;
					x = wiringPiI2CRead(digipot->digipot_setUpIO) ;	
					if (x > -1)
					{	// convert tap position to attenuation in dB
						double tap = -(x - digipot->wiper_positions) ;
						double ratio ;
						if (digipot->digipot_0_position[loop] == "RIGHT")
						{
							ratio = ((digipot->wiper_positions - tap) / (digipot->wiper_positions -1)) ;
						}
						else if (digipot->digipot_0_position[loop] == "CENTER")
						{
							ratio = ((digipot->wiper_positions - tap) / ((digipot->wiper_positions/2) -1)) ;
						}
						else
						{
							printf("\n!!! ZERO position value not recognized !!!\n") ;
							printf("ELSE-digipot->digipot_0_position[loop]:%s",digipot->digipot_0_position[loop]) ;
						}
						double dB = (20 * log10(ratio)) ;
						digipot->digipot_att[loop] = dB ; // store the digipot attenuation in dB
	//					printf("\n>>> Digipot Read response : x:%d - tap:%-0.0f - att:%0.2f(dB) \n", x, tap, dB) ;
						
	/*					printf(">>> Digipot Read addr: Ox%x = %d - setUpIO: 0x%x = %d - slaveAddressByte: 0x%x = %d - instructionByte: 0x%x = %d - dataByte/att: 0x%x = %3.2f(dB) \n", 
								digipot->digipot_address, digipot->digipot_address, digipot->digipot_setUpIO, digipot->digipot_setUpIO, slaveAddressByte, slaveAddressByte, instructionByte, instructionByte, x, dB) ;
	*/
					}
					else // stacked digipots drived simultaneously (grouped t oform a single serial or parallel SUPERDIGIPOT)
					{
						printf("\n!!! - Digipot Read error - !!!\n") ;
					}
					found = 1 ;
	//				printf("found digipot") ;
					break ;
				}
				else
				{
					// superdigipot = group (stack) of real digipots
				}
			}
//			printf("boucle 1 \n") ;
			if (found == 1) 
			{
				break ;
			}
		}
//		printf("boucle 2 \n") ;
		if (found == 1) 
		{
			break ;
		}
	}
//	printf("sortie de boucle 2 \n") ;
	return x ;
}
示例#17
0
void ADXL345::setBandwidthRate(int rate_flag)
{
  //printf("%d",rate_flag);
  wiringPiI2CWriteReg8(FD_ADDR,BW_RATE,rate_flag);
}
示例#18
0
文件: oled.c 项目: sunkaokao/test
void oled_WriteData(uint8_t fd, uint8_t data)
{
	wiringPiI2CWriteReg8(fd, 0x40, data);
}
示例#19
0
文件: oled.c 项目: sunkaokao/test
void oled_WriteCmd(uint8_t fd, uint8_t cmd)
{
	wiringPiI2CWriteReg8(fd, 0x00, cmd);
}
示例#20
0
文件: I2Cdev.cpp 项目: sanwave/Razor
void I2Cdev::writeByte(int devAddr, uint8_t regAddr, uint8_t data) {
    wiringPiI2CWriteReg8(devAddr,regAddr,  data);
}
示例#21
0
文件: main.c 项目: warshall/Raspi
void* Jeux(void* data)
{
 struct arg_jeux *e = data ;
 int Mcp = e->Mcp ;
 int J = e->J ;
 int *EtatLed = e->EtatLed ;
 int Ht16k = e->Ht16k ;
 
 
 
 if (J == 0)
 {

 wiringPiI2CWriteReg8 (Mcp, GPIO, LEDNOT) ;
   *EtatLed = LEDNOT ;
 }

 if (J == 1)
 {
   wiringPiI2CWriteReg8 (Mcp, GPIO, LEDALL) ;
   *EtatLed = LEDALL ;
 }

 if  (J == 2)
 {
  wiringPiI2CWrite (Ht16k, 0x81) ;

   while (1)
   {
      wiringPiI2CWriteReg8 (Mcp, GPIO, LEDNOT) ;
      *EtatLed = LEDNOT ;
      delay (500) ;
      wiringPiI2CWriteReg8 (Mcp, GPIO, LEDALL) ;
      *EtatLed = LEDALL ;
      delay (500) ;
    
	}
 }

 if  (J == 3)
 {
  wiringPiI2CWrite (Ht16k, 0x81) ;

   while (1)
    {
      wiringPiI2CWriteReg8 (Mcp, GPIO, LEDG) ;
      *EtatLed = LEDG ;
      delay (500) ;
      wiringPiI2CWriteReg8 (Mcp, GPIO, LEDD) ;
      *EtatLed = LEDD ;
      delay (500) ;
    }
 }

 if  (J == 4)
 {
   wiringPiI2CWrite (Ht16k, 0x81) ;
 
   while (1)
    {
      int b;
	  int LED[7] = {0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20};

      for (b = 0 ; b < 7 ; b++)
      {
        wiringPiI2CWriteReg8 (Mcp, GPIO, LED[b]) ;
        *EtatLed = LED[b] ;
	    delay (500);
      }	
 	 
	  for (b = 6 ; b > 0 ; b--)
      {
        wiringPiI2CWriteReg8 (Mcp, GPIO, LED[b]) ;
        *EtatLed = LED[b] ;
	    delay (500);
      }
	    
    }
 }

}
示例#22
0
文件: I2Cdev.cpp 项目: sanwave/Razor
void I2Cdev::writeBytes(int devAddr, uint8_t regAddr, uint8_t length, uint8_t* data) {
    for (uint8_t i = 0; i < length; ++i) {
		wiringPiI2CWriteReg8(devAddr, regAddr+i, data[i]);
	}
}
示例#23
0
int cPwmBoard::setPwmAll(float duty)
{
    int val = 4096 * duty;  //4096 values in PWM
    int high = val/256;    //High byte
    int low = val-high;      //Low byte

    #ifdef PWM_DEBUG
    std::cout<<"PWM | Writing to "<<std::hex<<PWM_ALL_ON<<" with value "<<std::hex<<high<<"|"<<std::hex<<low<<std::dec<<std::endl;
    #endif

    #ifdef LOGGING_FULL
    logfile << "PWM | Writing to " << std::hex<<PWM_ALL_ON << " with value " << std::hex<<high << "|" << std::hex<<low <<std::dec << std::endl;
    #endif
    piLock(0);
    if(wiringPiI2CWriteReg8(pwmFd,PWM_ALL_ON,0)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | Setting all PWM failed ("<<std::hex<< PWM_ALL_ON <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | Setting all PWM failed (" << std::hex<<PWM_ALL_ON <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    if(wiringPiI2CWriteReg8(pwmFd,PWM_ALL_ON+1,0)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | Setting all PWM failed ("<<std::hex<< PWM_ALL_ON+1 <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | Setting all PWM failed (" << std::hex<<PWM_ALL_ON+1 <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    if(wiringPiI2CWriteReg8(pwmFd,PWM_ALL_OFF,low)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | Setting all PWM failed ("<<std::hex<< PWM_ALL_ON+2 <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | Setting all PWM failed (" << std::hex<<PWM_ALL_ON+2 <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    if(wiringPiI2CWriteReg8(pwmFd,PWM_ALL_OFF+1,high)<0)
    {
        #ifdef PWM_DEBUG
        std::cout<<"PWM | Setting all PWM failed ("<<std::hex<< PWM_ALL_ON+3 <<std::dec<<")"<<std::endl;
        #endif

        #ifdef LOGGING_FULL
        logfile << "PWM | Setting all PWM failed (" << std::hex<<PWM_ALL_ON+3 <<std::dec << ")" << std::endl;
        #endif

        return -1;
    }
    piUnlock(0);
    return 0;
}
示例#24
0
/*
* Writes a full byte to the pin register.
*
* This function should always be used in favour of wiringPiI2CWriteReg8() as it tracks current state
*/
void write_pins(int value) {
	wiringPiI2CWriteReg8(fd, lcd_pin_register, value);
	current_register_value = value;
}
void ImuInterface::prepare()
{
    wiringPiI2CWriteReg8(handle, 0x3d, 0b00001100); //tryb NDOF
}
示例#26
0
int resetPCA9685(int fd) {
	wiringPiI2CWriteReg8(fd,0,0);
}
示例#27
0
/*
* Sets all pins to output and turns them off
*/
void reset_all() {
	wiringPiI2CWriteReg8(fd, lcd_io_register, 0x00); // All pins output
	write_pins(0x00); // All pins off
}
示例#28
0
int write8(int addr, int data) {
  return wiringPiI2CWriteReg8(fd, addr, data);
}
示例#29
0
void* myThread(void* param)
{
	unsigned int nInt = 0;
	struct threadParams* p = (struct threadParams*) param;
	int fd = p->fd ;
	unsigned int nStamp;
	int tid = pthread_self() ;
	int value=HIGH ;
	int longpress = 0;
	// set up to generate interrupts on INTB on pin B0 <> default value (1)
	//wiringPiI2CWriteReg8 (fd, MCP23x17_IODIRB, 0x03) ;
	wiringPiI2CWriteReg8 (fd, MCP23x17_IOCONB, 0b01101100) ; 
	// 7. register banks same, 6.mirror interrupts, 5.enable sequential mode, 4.DSSLW enabled, 3.HAEN=1, 2.open drain=0, 1.active-low, 0.unimpl
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_IOCONB ); // Read
	printf("IOCONB="); bin_prnt_byte(nInt);
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_INTCONB ); // Read
	printf("INTCONB(Before)="); bin_prnt_byte(nInt);
	wiringPiI2CWriteReg8 (fd, MCP23x17_INTCONB, 0b00000001) ; 
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_INTCONB ); // Read
	printf("INTCONB="); bin_prnt_byte(nInt);
	wiringPiI2CWriteReg8 (fd, MCP23x17_GPPUB, 0x01) ; // pull-up resistor for switches - 5 B ports
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPPUB ); // Read
	printf("GPPUB="); bin_prnt_byte(nInt);
	wiringPiI2CWriteReg8 (fd, MCP23x17_IPOLB, 0x01) ; // invert polarity of signal
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_IPOLB ); // Read
	printf("IOPOLB="); bin_prnt_byte(nInt);
	wiringPiI2CWriteReg8 (fd, MCP23x17_GPINTENB, 0x01) ; // enable interrupts
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPINTENB ); // Read
	printf("GPINTENB="); bin_prnt_byte(nInt);
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_INTCAPB ); // clear interrupt flag
	printf("INTCAPB-") ;
	bin_prnt_byte(nInt) ;
	nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPIOB ); // clear interrupt 
	printf("GPIOB="); bin_prnt_byte(nInt);

	printf("Port B setup completed.\n") ;

	//wiringPiI2CWriteReg8 (fd, MCP23x17_IODIRB, 0x1f) ;
	//wiringPiI2CWriteReg8 (fd, MCP23x17_INTCONB, 0x1f) ;
	//wiringPiI2CWriteReg8 (fd, MCP23x17_DEFVALB, 0x1f) ;
	//wiringPiI2CWriteReg8 (fd, MCP23x17_GPINTENB, 0x1f) ;
	//wiringPiI2CReadReg8 (fd, MCP23x17_INTCAPB ); // clear interrupt flag
	printf("%d: Interrupt thread started...\n", tid) ;
	while (g_ShouldRun)
	{
		if (g_Interrupt)
		{
			nStamp = millis() ;
			printf("\n\nInterrupt handling @ %d\n", nStamp) ;
			while (wiringPiI2CReadReg8 (fd, MCP23x17_GPIOB) == 0x01 ) 
			{
				// Loop to detect long press
				//break ;
				printf(".") ;
				delay (100) ;
			}
			g_Interrupt = 0;
			printf("\n") ;

			longpress = (millis() - nStamp);

			if ( longpress <= 500)
				g_EndBlink = !(g_EndBlink);
			else
			{
				printf("Time interval (for longpress) - %d\n", longpress) ;
				invLED(p, value) ;
				value = !value;
			}
			printf("Processed in %dms\n",longpress) ;
			delay (100); //debounce
			printf("Clearing registers...\n") ;
			nInt = wiringPiI2CReadReg8 (fd, MCP23x17_INTCAPB ); // clear interrupt 
			printf("INTCAPB="); bin_prnt_byte(nInt);
			nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPIOB ); // clear interrupt 
			printf("GPIOB="); bin_prnt_byte(nInt);

//			nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPINTENB ); // Read
//			printf("GPINTENB(Before)="); bin_prnt_byte(nInt);
//			wiringPiI2CWriteReg8 (fd, MCP23x17_GPINTENB, 0b00000001) ; 
//			nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPINTENB ); // Read
//			printf("GPINTENB="); bin_prnt_byte(nInt);
//			nInt = wiringPiI2CReadReg8 (fd, MCP23x17_INTCAPB ); // clear interrupt 
//			printf("INTCAPB="); bin_prnt_byte(nInt);
//			nInt = wiringPiI2CReadReg8 (fd, MCP23x17_GPIOB ); // clear interrupt 
//			printf("GPIOB="); bin_prnt_byte(nInt);
			
		}
		delay(500);
	}
	printf("%d: Interrupt thread cleaning up...\n", tid) ;

	return NULL;
}
示例#30
0
int vendor_fy(void)
{
	//You need to add a valid 16 byte vendor key in Hex
	unsigned char vendor_key1[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
					0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
	unsigned char man_id[49];
	unsigned long crc_32;
	unsigned char vendor_crc[4];
	unsigned char vendor_id[16];
	unsigned char serial_id[16];
	int i;

	//Copy eeprom SFP details into A50
	if(!read_eeprom(0x50)); else exit(EXIT_FAILURE);

	memcpy(&vendor_id, &A50[20],16);
	memcpy(&serial_id, &A50[68],16);

	//vendor_tmp holds = man_id 1 byte + 16 byte vendor + 16 byte serial + 
	//  16 byte vendor_key1
	man_id[0] = 0x00; //You need to provide a manufacturer id number. 
	for(i = 1; i <17; i++)
		man_id[i] = vendor_id[i-1];
	for(i = 17; i <33; i++)
		man_id[i] = serial_id[i-17];
	for(i = 33; i <49; i++)
		man_id[i] = vendor_key1[i-33];
	//need to calculate the md5 of the concatenated string
	//using openssl envelope functions from openssl libcrypto
	EVP_MD_CTX *mdctx;
        const EVP_MD *md;
	unsigned char md_value[EVP_MAX_MD_SIZE];
        int md_len;

	OpenSSL_add_all_digests();
	mdctx = EVP_MD_CTX_create();
		md = EVP_get_digestbyname("md5");
		EVP_DigestInit_ex(mdctx, md, NULL);
		EVP_DigestUpdate(mdctx, man_id, 49);
		EVP_DigestFinal_ex(mdctx, md_value, &md_len);
        //clean up
		EVP_MD_CTX_destroy(mdctx);

	printf("\nDigest is: ");
	for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);

	//Create valid id
		    unsigned char vendor_trailer[9+1] = {0x00,0x00,0x00,0x00,0x00
							,0x00,0x00,0x00,0x00};
		    unsigned char vendor_valid_id[28+1];
		    vendor_valid_id[0] = 0x00;
		    vendor_valid_id[1] = 0x00;
		    vendor_valid_id[2] = man_id[0];//first byte of man_id.
		    for(i = 0; i < 16; i++)
			    vendor_valid_id[i+3] = md_value[i];
		    for(i = 0; i < 10; i++)
			    vendor_valid_id[i+19] = vendor_trailer[i];
		    printf("\nVendor Valid Id = ");
		    for(i=0; i < 29; i++) printf("%x",vendor_valid_id[i]);

	//write the vendor_valid_id from address 96(0x60) to address 124(0x7b) 
	printf("\nWrite valid_vendor_id Yes/No?");
		int ch = 0;
		ch = getchar();
		getchar();
		if ((ch == 'Y') || (ch == 'y'))
		{
			printf("Writing Digest wait....\n");
#ifdef BEAGLEBONE
            xio = open(filenm, O_RDWR);
            if (xio < 0) {
              fprintf (stderr, "Unable to open device: %s\n", filenm);
              return(1);
            }

            if (ioctl(xio, I2C_SLAVE, 0x50) < 0) {
                fprintf (stderr, "xio: Unable to initialise I2C: %s\n", strerror (errno));
                return(1);
            }
#else
			xio = wiringPiI2CSetup (0x50);
				if (xio < 0){
				fprintf (stderr, "xio: Unable to initialise I2C: %s\n",
                                strerror (errno));
				return 1;
				}
#endif
			for(i = 0; i < 28; i++) {
#ifndef BEAGLEBONE
			wiringPiI2CWriteReg8(xio, 0x60+i, vendor_valid_id[i]);
#else
            i2c_smbus_write_byte_data(xio, 0x60+i, vendor_valid_id[i]);
#endif
			usleep(50000);//sleep for 0.5ms per byte 
			}
		} else printf("nothing written");

	//now need to get the crc32 of the header+md5+trailer
	crc_32 = crc32(0, vendor_valid_id, 28);

	//printf("\nvalue of returned crc = %x",crc_32);
		vendor_crc[0] = (int) crc_32 & 0xff; //A50[124]
		vendor_crc[1] = (int) crc_32 >> 8 & 0xff; //A50[125]
		vendor_crc[2] = (int) crc_32 >> 16 & 0xff;//A50[126]
		vendor_crc[3] = (int) crc_32 >> 24 & 0xff;//A50[127]
		printf("\nCRC32 of the Vendor Padded MD5 =");
		for(i = 0; i < 4; i++) printf(" %x", vendor_crc[i]);
	//need to write the crc values to the eeprom
	//
	printf("\nWrite CRC32 of the padded Digest in reverse (4 seconds) Yes/No?");
		ch =0;
		ch = getchar();
		getchar();
		if ((ch == 'Y') || (ch == 'y'))
		{
			printf("Writing CRC32 wait....\n");
#ifndef BEAGLEBONE
			xio = wiringPiI2CSetup (0x50);
				if (xio < 0){
				fprintf (stderr, "xio: Unable to initialise I2C: %s\n",
                                strerror (errno));
				return 1;
				}
#else
            xio = open(filenm, O_RDWR);
            if (xio < 0) {
              fprintf (stderr, "Unable to open device: %s\n", filenm);
              return(1);
            }

            if (ioctl(xio, I2C_SLAVE, 0x50) < 0) {
                fprintf (stderr, "xio: Unable to initialise I2C: %s\n", strerror (errno));
                return(1);
            }
#endif
			for(i = 0; i < 4; i++)
			{
#ifndef BEAGLEBONE
			wiringPiI2CWriteReg8(xio, 0x7c+i,vendor_crc[i]);
#else
            i2c_smbus_write_byte_data(xio, 0x7c+i, vendor_crc[i]);
#endif
			usleep(50000);//wait 0.5ms per byte
			}
		} else printf("nothing written\n");
	if (write_checksum)
	{
	//Calculate the checksum: Add up the first 31 bytes and store
	//the last 8 bits in the 32nd byte
	mychecksum(0x0, 0x3f);

	//Calculate the extended checksum: Add up 31 bytes and store
	//the last 8 bits in the 32nd byte
	mychecksum(0x40, 0x5f);
	}
	return 0;
}