Ejemplo n.º 1
0
Archivo: RF24.c Proyecto: neostarr/RF24
uint8_t flush_tx(void)
{
  uint8_t status;

  csn(LOW);
  status = spiSendData( FLUSH_TX );
  csn(HIGH);

  return status;
}
Ejemplo n.º 2
0
Archivo: RF24.c Proyecto: neostarr/RF24
uint8_t read_payload(unit8_t* buf, uint8_t len)
{
  uint8_t status;

  uint8_t data_len = min(len,payload_size);
  uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
  
  //printf("[Reading %u bytes %u blanks]",data_len,blank_len);
  
  csn(LOW);
  status = spiSendData( R_RX_PAYLOAD );
  while ( data_len-- )
    *buf++ = spiSendData(0xff);
  while ( blank_len-- )
    spiSendData(0xff);
  csn(HIGH);

  return status;
}
Ejemplo n.º 3
0
Archivo: RF24.c Proyecto: neostarr/RF24
uint8_t write_payload(const uint8_t* buf, uint8_t len)
{
  uint8_t status;

  uint8_t data_len = min(len,payload_size);
  uint8_t blank_len = dynamic_payloads_enabled ? 0 : payload_size - data_len;
  
  //printf("[Writing %u bytes %u blanks]",data_len,blank_len);
  
  csn(LOW);
  status = spiSendData( W_TX_PAYLOAD );
  while ( data_len-- )
    spiSendData(*buf++);
  while ( blank_len-- )
    spiSendData(0);
  csn(HIGH);

  return status;
}
Ejemplo n.º 4
0
void BnrOneA::movePID(int speedL,int speedR)
{
    byte speedL_H=highByte(speedL);
    byte speedL_L=lowByte(speedL);
    byte speedR_H=highByte(speedR);
    byte speedR_L=lowByte(speedR);

    byte buffer[]={KEY1,KEY2,speedL_H,speedL_L,speedR_H,speedR_L};
    spiSendData(COMMAND_MOVE_PID,buffer,sizeof(buffer));
    delay(5);//Wait while command is processed
}
Ejemplo n.º 5
0
/**
 * Send configuration data to the slave
 *
 *
 * Input    :   address     is the address of the configuration register
 *              data        is the data going to be written into the configuration register
 *
 * Output   :   1 for OK
 *              0 for failure as the master did not receive ACK from the slave
 */
uint8 spiSendConfig(uint32 address,uint8 *data)
{

    if(!spiSendCommand(CONFIG))
        return 0;
    if(!spiSendAddressOnly(address))
        return 0;
    if(!spiSendData(data,1,0))
        return 0;

    return 1 ;
}
Ejemplo n.º 6
0
void BnrOneA::minBat(float batmin)
{
    int intg=(int)batmin;
    int dec=(int)((batmin-intg)*1000);
    byte intg_H=highByte(intg);
    byte intg_L=lowByte(intg);
    byte dec_H=highByte(dec);
    byte dec_L=lowByte(dec);
    byte buffer[]={KEY1,KEY2,intg_H,intg_L,dec_H,dec_L};
    spiSendData(COMMAND_BAT_MIN,buffer,sizeof(buffer));
    delay(25);//Wait while command is processed
}
Ejemplo n.º 7
0
///////////////////////////////////////////////////////////////////////
//private routines
///////////////////////////////////////////////////////////////////////
byte BnrOneA::spiRequestByte(byte command)
{
    byte value=(byte)0xFF;
    byte buffer[]={KEY1,KEY2};
    spiSendData(command,buffer,sizeof(buffer));//Request data from master
    digitalWrite(_sspin, LOW); // Select the SPI Slave device to start communication.
    delayMicroseconds(10);
    value=SPI.transfer(0x00);  // Reads one byte
    delayMicroseconds(60);
    digitalWrite(_sspin, HIGH); // Close communication with slave device.
    delayMicroseconds(10);
    return value;
}
Ejemplo n.º 8
0
void BnrOneA::setPID(int kp, int ki, int kd)
{
    byte kp_H=highByte(kp);
    byte kp_L=lowByte(kp);
    byte ki_H=highByte(ki);
    byte ki_L=lowByte(ki);
    byte kd_H=highByte(kd);
    byte kd_L=lowByte(kd);

    byte buffer[]={KEY1,KEY2,kp_H,kp_L,ki_H,ki_L,kd_H,kd_L};
    spiSendData(COMMAND_PID_CFG,buffer,sizeof(buffer));
    delay(20);//Wait while command is processed
}
Ejemplo n.º 9
0
/**
 * Send specific address to the slave
 * Note     :   For sending configuration words and reading device ID purpose only
 *
 * Input    :   address     is the specific address to be sent to the slave
 *
 * Output   :   1 for OK
 *              0 for failure as the master did not receive ACK from the slave
 */
uint8 spiSendAddressOnly(uint32 address)
{
    uint8 addressArray[3] ;
    addressArray[0] = address ;
    addressArray[1] = address >> 8 ;
    addressArray[2] = address >> 16 ;

    if(!spiSendData(addressArray,3,0))
        return 0 ;
    else
        return 1 ;

}
void Emutex_MAX9657::resetOutputs(void) {
    if (!initialised)
        return;

    for (byte reg = 0; reg < sizeof(port_data_reg_addr); reg++) {
        byte len = 0;
        for (byte dev = 0; dev < ndev; dev++) {
            output_state[dev][reg] = 0x0;
            spidata[len++] = port_data_reg_addr[reg];
            spidata[len++] = output_state[dev][reg];
            do_refresh[dev][reg] = false;
        }
        spiSendData(len);
    }
}
Ejemplo n.º 11
0
/**
 * Send starting address of a segment to the slave
 *
 * Input    :   fb      contains the segment number
 *
 * Output   :   1       for OK
 *              0       for failure as the master did not receive ACK from the slave
 */
uint8 spiSendAddressSegment(FlashBuffer *fb)
{
    uint8 addressArray[3] ;

    uint32 address = fb->segment * 0x40;

    addressArray[0] = address ;
    addressArray[1] = address >> 8 ;
    addressArray[2] = address >> 16 ;

    if(!spiSendData(addressArray,3,0))
        return 0 ;
    else
        return 1 ;
}
Ejemplo n.º 12
0
void BnrOneA::lcd1(long int number)
{
    int i, a=0;
    byte buffer[19];
    char string[17];
    a=sprintf(string,"%ld",number);
    buffer[0]=KEY1;
    buffer[1]=KEY2;
    for(i=0;i<16;i++){
        buffer[i+2]=string[i];
    }
    for(i=a;i<16;i++){
        buffer[i+2]=(' ');
    }
    spiSendData(COMMAND_LCD_L1,buffer,sizeof(buffer));
    delay(19);//Wait while command is processed
}
Ejemplo n.º 13
0
void BnrOneA::lcd2(unsigned int num1, unsigned int num2, unsigned int num3)
{
    int i, a=0;
    byte buffer[19];
    char string[17];
    a=sprintf(string,"%5u%5u%5u",num1,num2,num3);
    buffer[0]=KEY1;
    buffer[1]=KEY2;
    for(i=0;i<16;i++){
        buffer[i+2]=string[i];
    }
    for(i=a;i<16;i++){
        buffer[i+2]=(' ');
    }
    spiSendData(COMMAND_LCD_L2,buffer,sizeof(buffer));
    delay(19);//Wait while command is processed
}
Ejemplo n.º 14
0
void BnrOneA::lcd1(const char string[],double number)
{
    int i, a, b;
    char string1[19];
    char string2[19];
    byte buffer[19];
    int intg, dec;
	bool flag_neg=0;

    for(i=0;i<16;i++){
        string2[i]=string[i];
    }
    string2[16]=0;    
    a=sprintf(string1,string2);    
	buffer[0]=KEY1;
    buffer[1]=KEY2;
    for(i=0;i<a;i++){
        buffer[i+2]=string1[i];
    }
    a+=2;
	if (number<-0.0001){
		flag_neg=1;
		number*=-1.0;
	}
	dec = round((number-((double)(int)number))*100.0) % 100;
	intg = (dec==0 ? round(number):(int)number);
    b=sprintf(string2,"%d.%02d            ",intg,dec);
	if (flag_neg==1){
		buffer[a]='-';
		a++;
	}		
    for(i=0;i<b;i++){
		if((i+a)<18)
			buffer[i+a]=string2[i];
    }
	for(i=0;i<18;i++){
		Serial.println(buffer[i],DEC);
	}
	Serial.println();
    spiSendData(COMMAND_LCD_L1,buffer,sizeof(buffer));
    delay(19);//Wait while command is processed
}
void Emutex_MAX9657::updateOutputs(void) {
    if (!initialised)
        return;

    for (byte reg = 0; reg < sizeof(port_data_reg_addr); reg++) {
        byte len = 0;
        for (byte dev = 0; dev < ndev; dev++) {
            if (do_refresh[dev][reg]) {
                spidata[len++] = port_data_reg_addr[reg];
                spidata[len++] = output_state[dev][reg];
                do_refresh[dev][reg] = false;
            } else {
                spidata[len++] = ADDR_NO_OP;
                spidata[len++] = 0;
            }
        }
        if (len)
            spiSendData(len);
    }
}
Ejemplo n.º 16
0
void BnrOneA::lcd2(byte string[])
{
    int i,a;
    byte buffer[19];
    char string1[19],string2[19];
    for(i=0;i<16;i++){
        string2[i]=string[i];
    }
    string2[16]=0;
    a=sprintf(string1,string2);
    buffer[0]=KEY1;
    buffer[1]=KEY2;
    for(i=0;i<a;i++){
        buffer[i+2]=string1[i];
    }
    for(i=a;i<16;i++){
        buffer[i+2]=' ';
    }
    spiSendData(COMMAND_LCD_L2,buffer,sizeof(buffer));
    delay(19);//Wait while command is processed
}
Ejemplo n.º 17
0
int BnrOneA::spiRequestWord(byte command)
{
    byte value[2]={0,0};
    int i=0;
    byte buffer[]={KEY1,KEY2};
    spiSendData(command,buffer,sizeof(buffer));//Request data from master
    digitalWrite(_sspin, LOW); // Select the SPI Slave device to start communication.
    delayMicroseconds(10);
    for (i=0; i<2; i++)
    {
        value[i]=SPI.transfer(0x00);  // Reads one byte
        delayMicroseconds(60);
    }
    i=0;
    i=value[0];
    i=i<<8;
    i=i+value[1];
    digitalWrite(_sspin, HIGH); // Close communication with slave device.
    delayMicroseconds(10);
  return i;
}
Ejemplo n.º 18
0
void BnrOneA::brake(byte torqueL,byte torqueR)
{
    byte buffer[]={KEY1,KEY2,torqueL,torqueR};
    spiSendData(COMMAND_BRAKE,buffer,sizeof(buffer));
    delay(5);//Wait while command is processed
}
Ejemplo n.º 19
0
void BnrOneA::stop()
{
    byte buffer[]={KEY1,KEY2};
    spiSendData(COMMAND_STOP,buffer,sizeof(buffer));
    delay(5);//Wait while command is processed
}
Ejemplo n.º 20
0
void BnrOneA::stop1m(byte motor)
{
    byte buffer[]={KEY1,KEY2,motor};
    spiSendData(COMMAND_STOP_1M,buffer,sizeof(buffer));
    delay(5);//Wait while command is processed
}
Ejemplo n.º 21
0
void BnrOneA::brake1m(byte motor)
{
    byte buffer[]={KEY1,KEY2,motor,BRAKE_TORQUE};
    spiSendData(COMMAND_BRAKE_1M,buffer,sizeof(buffer));
    delay(5);//Wait while command is processed
}
Ejemplo n.º 22
0
void BnrOneA::resetEncR()
{
    byte buffer[]={KEY1,KEY2};
    spiSendData(COMMAND_ENCR_RESET,buffer,sizeof(buffer));
    delay(1);//Wait while command is processed
}
Ejemplo n.º 23
0
void BnrOneA::servo2(byte position)
{
    byte buffer[]={KEY1,KEY2,position};
    spiSendData(COMMAND_SERVO2,buffer,sizeof(buffer));
    delay(2);//Wait while command is processed
}