s5tech.net • Poglej temo - PoStep60 in I2C

PoStep60 in I2C

Tu bo govora o vseh mogočih mikrokontrolerjih ne glede na tip ali zgradbo

Moderator: tilz0R

PoStep60 in I2C

OdgovorNapisal/-a s54mtb » 27 Apr 2016, 00:37

Zanima me, ali kdo uporablja PoStep60 in mu pošilja komande preko I2C in v kakšni aplikaciji ?
s54mtb
 
Prispevkov: 8031
Pridružen: 15 Jan 2015, 01:10
Zahvalil se je: 1032 krat
Prejel zahvalo: 2560 krat
Uporabnika povabil: Vrtni palček
Število neizkoriščenih povabil: 54

Re: PoStep60 in I2C

OdgovorNapisal/-a s54mtb » 30 Apr 2016, 22:56

Očitno nihče.

Če bi se morda kdo odločil, je tule skupek funkcij za upravljanje preko I2C. Potrebna je implementacija dveh funkcij, ki sta odvisna od mikrokontrolerja, na katerem je I2C in sicer:

Koda: Izberi vse
extern int32_t M_I2CTransmit(uint32_t addr, uint8_t *data, uint32_t num);
extern int32_t M_I2CReceive(uint32_t addr, uint8_t *data, uint32_t num);


Tole je POSTEP60.H
Koda: Izberi vse

#ifndef ___POSTEP60_H__
#define ___POSTEP60_H__

/**
 * @brief  Driver Mode
 */
typedef enum
{
   POSTEP_SLEEP,
   POSTEP_RUN
} POSTEP_MODE_t;


/**
 * @brief  Driver HW/SW info
 */
typedef struct
{
  uint8_t ID;         /// 0x41 – driver ID
   uint8_t HW_M;      /// HW version major release
   uint8_t HW_m;      /// HW version minor release
   uint8_t FW_M;      /// FW version major release
   uint8_t FW_m;      /// FW version minor release
} POSTEP_INFO_t;




/**
 * @brief  Loopback read: test a response of PoStep60 driver
 * @param    addr: I2C address of PoStep60 module
 */
uint32_t POSTEP_LoopBack(uint32_t addr);


/**
 * @brief  Set Run/Sleep mode: enable or disable (Run/Sleep) the driver
 * @param    addr: I2C address of PoStep60 module
 * @param  mode: POSTEP_RUN or POSTEP_SLEEP
 * @retval I2C status
 */
uint32_t POSTEP_SetMode(uint32_t addr, POSTEP_MODE_t mode);


/**
 * @brief  Read HW/FW info
 * @paramIn    addr: I2C address of PoStep60 module
 * @paramOut POSTEP_INFO
 * @retval I2C status
 */
uint32_t POSTEP_ReadInfo(uint32_t addr, POSTEP_INFO_t *info);


/**
 * @brief  Read voltage
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Supply voltage
 */
float POSTEP_ReadVoltage(uint32_t addr);


/**
 * @brief  Read temperature
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver Internal temperature
 */
float POSTEP_ReadTemperature(uint32_t addr);


/**
 * @brief  Read position
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver current position
 */
int32_t POSTEP_ReadPosition(uint32_t addr);


/**
 * @brief  Read maximal speed
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver maximal speed
 */
uint16_t POSTEP_ReadMaxSpeed(uint32_t addr);


/**
 * @brief  Read acceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver acceleration
 */
uint16_t POSTEP_ReadAcceleration(uint32_t addr);



/**
 * @brief  Read deceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver deceleration
 */
uint16_t POSTEP_ReadDeceleration(uint32_t addr);


/**
 * @brief  Set position
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetPosition(uint32_t addr, int32_t position);


/**
 * @brief  Set zero
 * @paramIn    addr: I2C address of PoStep60 module
 */
int32_t POSTEP_SetZero(uint32_t addr);


/**
 * @brief  Stop!
 * @paramIn    addr: I2C address of PoStep60 module
 */
int32_t POSTEP_Stop(uint32_t addr);


/**
 * @brief  Set maximal speed
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetMaxSpeed(uint32_t addr, int16_t maxspeed);


/**
 * @brief  Set acceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetAcceleration(uint32_t addr, int16_t acceleration);


/**
 * @brief  Set deceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetDeceleration(uint32_t addr, int16_t deceleration);



#endif






Pa še POSTEP60.C
Koda: Izberi vse
/**
 * @author  Marko Pavlin
 * @email   m@v4.si
 * @website http://pavlin.si
 * @version v1.0
 * @ide     Keil uVision
 * @license GNU GPL v3
 * @brief   Driver library for PoStep60 via I2C interface
 *   
\verbatim
   ----------------------------------------------------------------------
    Copyright (C) Marko Pavlin, 2016
   
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    any later version.
     
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
   
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
   ----------------------------------------------------------------------
\endverbatim
 */


#include "postep60.h"
#include <string.h>

extern int32_t M_I2CTransmit(uint32_t addr, uint8_t *data, uint32_t num);
extern int32_t M_I2CReceive(uint32_t addr, uint8_t *data, uint32_t num);


/**
  PoStep60 I2C IO functions:
    0x01 - Loopback read
      0x03 – Set Run/Sleep mode
      0x0A – Read HW/FW info
      0x10 – Read voltage
      0x11 – Read temperature
      0x12 – Read pin statuses
      0x13 – Read driver status
      0x14 – Read driver mode
      0x20 – Read full scale current
      0x21 – Read idle current
      0x22 – Read overheat current
      0x23 – Read step mode
      0x24 – Read temperature limit
      0x25 – Read faults
      0x30 – Set full scale current
      0x31 – Set idle current
      0x32 – Set overheat current
      0x33 – Set step mode
      0x34 – Set temperature limit
      0x35 – Reset faults
      0x3F – Write settings to EEPROM
      0x40 – Read position
      0x41 – Read maximal speed
      0x42 – Read acceleration
      0x43 – Read deceleration
      0x50 – Set position
      0x51 – Set maximal speed
      0x52 – Set acceleration
      0x53 – Set deceleration
      0x5E – Set zero
      0x5F – Stop
      
*/


/**
 * @brief  Loopback read: test a response of PoStep60 driver
 * @param    addr: I2C address of PoStep60 module
 * @retval 0... OK, -1... Loopback failed (PoStep not responding)
 */
uint32_t POSTEP_LoopBack(uint32_t addr)
{
  uint8_t data_array[5],i;
   
  /* Check I2C PoStep loopback */
   data_array[0] = 0x01; /* Command = 0x01 */
   data_array[1] = 0x11; /* Data 1 */
   data_array[2] = 0x22; /* Data 2 */
   data_array[3] = 0x33; /* Data 3 */
   data_array[4] = 0xcc; /* Data 4 */
   M_I2CTransmit (addr, data_array, 5);
   for (i = 0; i<5; i++) data_array[i]=0;
   M_I2CReceive(addr, &data_array[0], 5);
   return (data_array[2] != 0x22) ? -1 : 0;

}


/**
 * @brief  Set Run/Sleep mode: enable or disable (Run/Sleep) the driver
 * @param    addr: I2C address of PoStep60 module
 * @param  mode: POSTEP_RUN or POSTEP_SLEEP
 * @retval I2C status
 */
uint32_t POSTEP_SetMode(uint32_t addr, POSTEP_MODE_t mode)
{
  uint8_t data_array[2];
   
   data_array[0] = 0x03; /* Command 0x03 – Set Run/Sleep mode  */
   switch (mode)
   {
      case POSTEP_SLEEP:
         data_array[1] = 0x0f;
      break;
      
      case POSTEP_RUN:
         data_array[1] = 0xda;
      break;
   }

   return M_I2CTransmit (addr, data_array, 2);
}




/**
 * @brief  Read HW/FW info
 * @paramIn    addr: I2C address of PoStep60 module
 * @paramOut POSTEP_INFO
 * @retval I2C status
 */
uint32_t POSTEP_ReadInfo(uint32_t addr, POSTEP_INFO_t *info)
{
  uint8_t command;
   uint32_t status;
   uint8_t binfo[5];
   
   command = 0x0A; /* Command 0x0A – Read HW/FW info  */
   M_I2CTransmit (addr, &command, 1);
   status = M_I2CReceive(addr, binfo, 5);
   
   info->ID = binfo[0];
   info->HW_M = binfo[1];
   info->HW_m = binfo[2];
   info->FW_M = binfo[3];
   info->FW_m = binfo[4];

   return status;
}




/**
 * @brief  Read voltage
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Supply voltage
 */
float POSTEP_ReadVoltage(uint32_t addr)
{
  uint8_t command;
   uint8_t data[2];
   float voltage;
   
   command = 0x10; /* Command 0x10 – Read Read voltage  */
   M_I2CTransmit (addr, &command, 1);
   M_I2CReceive(addr, data, 2);
   
   voltage = (float)(data[1]*256 + data[0]) * 0.072f;
   
   return voltage;
}



/**
 * @brief  Read temperature
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver Internal temperature
 */
float POSTEP_ReadTemperature(uint32_t addr)
{
  uint8_t command;
   uint8_t data[2];
   float temperature;
   
   command = 0x11; /* Command 0x11 – Read Temperature  */
   M_I2CTransmit (addr, &command, 1);
   M_I2CReceive(addr, data, 2);
   
   temperature = (float)(data[1]*256 + data[0]) * 0.125f;
   
   return temperature;
}


/**
 * @brief  Read position
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver current position
 */
int32_t POSTEP_ReadPosition(uint32_t addr)
{
  uint8_t command;
   uint8_t data[4];
   int32_t position;
   
   command = 0x40; /* Command 0x40 – Read position  */
   M_I2CTransmit (addr, &command, 1);
   M_I2CReceive(addr, data, 4);
   
   // reorder little to big endian
   position = (data[3]<<24) | (data[2]<<16) | (data[1]<<8) | (data[0]<<0);
   return position;
   
}


/**
 * @brief  Read maximal speed
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver maximal speed
 */
uint16_t POSTEP_ReadMaxSpeed(uint32_t addr)
{
  uint8_t command;
   uint8_t data[2];
   int16_t maxspeed;
   
   command = 0x41; /* Command 0x41 – Read maximal speed */
   M_I2CTransmit (addr, &command, 1);
   M_I2CReceive(addr, data, 2);
   
   // reorder little to big endian
   maxspeed = (data[1]<<8) | (data[0]<<0);
   return maxspeed;
   
}



/**
 * @brief  Read acceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver acceleration
 */
uint16_t POSTEP_ReadAcceleration(uint32_t addr)
{
  uint8_t command;
   uint8_t data[2];
   int16_t acceleration;
   
   command = 0x42; /* Command 0x42 – Read acceleration */
   M_I2CTransmit (addr, &command, 1);
   M_I2CReceive(addr, data, 2);
   
   // reorder little to big endian
   acceleration = (data[1]<<8) | (data[0]<<0);
   return acceleration;
   
}



/**
 * @brief  Read deceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval PoStep Driver deceleration
 */
uint16_t POSTEP_ReadDeceleration(uint32_t addr)
{
  uint8_t command;
   uint8_t data[2];
   int16_t deceleration;
   
   command = 0x42; /* Command 0x42 – Read acceleration */
   M_I2CTransmit (addr, &command, 1);
   M_I2CReceive(addr, data, 2);
   
   // reorder little to big endian
   deceleration = (data[1]<<8) | (data[0]<<0);
   return deceleration;
   
}


/**
 * @brief  Set position
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetPosition(uint32_t addr, int32_t position)
{
   uint8_t data[5];
   
   data[0] = 0x50; /* Command 0x50 – Set position  */
   data[4] = (position>>24) & 0xff;
   data[3] = (position>>16) & 0xff;
   data[2] = (position>>8) & 0xff;
   data[1] = (position>>0) & 0xff;
   return M_I2CTransmit (addr, data, 5);   
}


/**
 * @brief  Set zero
 * @paramIn    addr: I2C address of PoStep60 module
 */
int32_t POSTEP_SetZero(uint32_t addr)
{
   uint8_t command;
   
   command = 0x5e; /* Command 0x5E – Set zero  */
   return M_I2CTransmit (addr, &command, 1);   
}


/**
 * @brief  Stop!
 * @paramIn    addr: I2C address of PoStep60 module
 */
int32_t POSTEP_Stop(uint32_t addr)
{
   uint8_t command;
   
   command = 0x5f; /* Command 0x5F – Stop  */
   return M_I2CTransmit (addr, &command, 1);   
}



/**
 * @brief  Set maximal speed
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetMaxSpeed(uint32_t addr, int16_t maxspeed)
{
   uint8_t data[3];
   
   data[0] = 0x51; /* Command 0x51 – Set maximal speed  */
   data[2] = (maxspeed>>8) & 0xff;
   data[1] = (maxspeed>>0) & 0xff;
   return M_I2CTransmit (addr, data, 3);   
}


/**
 * @brief  Set acceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetAcceleration(uint32_t addr, int16_t acceleration)
{
   uint8_t data[3];
   
   data[0] = 0x52; /* Command 0x52 – Set acceleration  */
   data[2] = (acceleration>>8) & 0xff;
   data[1] = (acceleration>>0) & 0xff;
   return M_I2CTransmit (addr, data, 3);   
}




/**
 * @brief  Set deceleration
 * @paramIn    addr: I2C address of PoStep60 module
 * @retval I2C status
 */
int32_t POSTEP_SetDeceleration(uint32_t addr, int16_t deceleration)
{
   uint8_t data[3];
   
   data[0] = 0x53; /* Command 0x53 – Set deceleration  */
   data[2] = (deceleration>>8) & 0xff;
   data[1] = (deceleration>>0) & 0xff;
   return M_I2CTransmit (addr, data, 3);   
}




LP,
M.
s54mtb
 
Prispevkov: 8031
Pridružen: 15 Jan 2015, 01:10
Zahvalil se je: 1032 krat
Prejel zahvalo: 2560 krat
Uporabnika povabil: Vrtni palček
Število neizkoriščenih povabil: 54

Re: PoStep60 in I2C

OdgovorNapisal/-a s54mtb » 30 Apr 2016, 23:00

I2C je na voljo na tistem rdečem cik-cak konektorju:
connector.JPG
s54mtb
 
Prispevkov: 8031
Pridružen: 15 Jan 2015, 01:10
Zahvalil se je: 1032 krat
Prejel zahvalo: 2560 krat
Uporabnika povabil: Vrtni palček
Število neizkoriščenih povabil: 54

Re: PoStep60 in I2C

OdgovorNapisal/-a LiPo » 01 Maj 2016, 22:53

Zivjo,

a ne bi raje naredil samostojnega kotrolerja.
Pa pac dravjal koračni motor preko CLK/DIR.
Se mi zdi kaj fajn uporabna moznost..
Uporabniški avatar
LiPo
 
Prispevkov: 673
Pridružen: 04 Apr 2015, 17:30
Kraj: LJUBLJANA
Zahvalil se je: 22 krat
Prejel zahvalo: 82 krat
Uporabnika povabil: cimabella
Število neizkoriščenih povabil: 16

Re: PoStep60 in I2C

OdgovorNapisal/-a s54mtb » 01 Maj 2016, 23:01

Že že, samo če uporabiš en res majhen mikrokontroler, ti potem ni potrebno skrbeti za pulse engine. Pa še vse ostalo lahko pokomuniciraš z driverjem. Take aplikacije niso v stilu CNC, ampak neka preprosta "migalica", kjer koračni motor uporabiš npr. namesto pnevmatskega cilindra, krmiliš ga pa preko I2C.
s54mtb
 
Prispevkov: 8031
Pridružen: 15 Jan 2015, 01:10
Zahvalil se je: 1032 krat
Prejel zahvalo: 2560 krat
Uporabnika povabil: Vrtni palček
Število neizkoriščenih povabil: 54

Re: PoStep60 in I2C

OdgovorNapisal/-a tilz0R » 01 Maj 2016, 23:59

Mare, všeč mi je začetek postep60.c datoteke :D

Drugače pa zgleda uporabna knjižnica!
Knowledge sharing is people' caring., T. MAJERLE
Uporabniški avatar
tilz0R
 
Prispevkov: 1441
Pridružen: 18 Jan 2015, 00:12
Kraj: Črnomelj
Zahvalil se je: 187 krat
Prejel zahvalo: 350 krat
Uporabnika povabil: s56rga
Število neizkoriščenih povabil: 255

Re: PoStep60 in I2C

OdgovorNapisal/-a s54mtb » 02 Maj 2016, 01:13

tilz0R je napisal/-a:Mare, všeč mi je začetek postep60.c datoteke :D

Drugače pa zgleda uporabna knjižnica!


Zahvala gre seveda tebi. Copy paste :)
s54mtb
 
Prispevkov: 8031
Pridružen: 15 Jan 2015, 01:10
Zahvalil se je: 1032 krat
Prejel zahvalo: 2560 krat
Uporabnika povabil: Vrtni palček
Število neizkoriščenih povabil: 54


Vrni se na Hardware

Kdo je na strani

Po forumu brska: 0 registriranih uporabnikov in 1 gost