cancel
Showing results for 
Search instead for 
Did you mean: 

Can anybody help me how to translate this for my nucleo?

Myilm.1
Associate II
 
21 REPLIES 21
Myilm.1
Associate II

I am using i2c1 and the communication is okay. The code below works fine.

if(HAL_I2C_IsDeviceReady(&hi2c1,TMP102_ADDR ,1,10)==HAL_OK){ 

  HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_7); }

But I couldn't make @Tesla DeLorean 's function work. I think i am quite rusty on programming. :(

Pavel A.
Evangelist III

TMP102_ADDR ?

Do you know the I2C address of MAX518? It is defined by some pins on the chip.

Use a logic analyzer to see if it asserts ACK after the STM32 sends the I2C address.

Yes, 0x2C.

I2C is very well-established & widely used - so lots of resources for learning; eg,

Full specification here: https://www.nxp.com/docs/en/user-guide/UM10204.pdf

https://en.wikipedia.org/wiki/I%C2%B2C

https://learn.sparkfun.com/tutorials/i2c/all

https://www.i2c-bus.org/specification/

https://i2c.info/

An all-too-common source of confusion is the (mis-)representation of the 7-bit address:

https://www.avrfreaks.net/comment/1872781#comment-1872781

:\

MM..1
Chief III

MAX normal control two out then you need send 4 BYTES over I2C .

D_Cmd= 0xFF01FF00;
	  HAL_I2C_Master_Transmit(&hi2cX, I2C_ADDR_MAX, (uint8_t *)&D_Cmd,4,5);

D_Cmd is uint32 ... you can use arrray instead and check HAL_OK returned

Can't make it work. Can you write more clear?​

On the STM32 you should use (0x2C << 1)

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Something along the lines of this, once interface set up

#define DAC_ADDR (0x2C << 1) // I2C bus address
#define DAC_CHANNEL 0
 
uint8_t SinLUT[] = { // Byte level Sine Lookup Table
  0x80,0x83,0x86,0x89,0x8C,0x8F,0x92,0x95,0x98,0x9C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,
  0xB0,0xB3,0xB6,0xB9,0xBC,0xBF,0xC1,0xC4,0xC7,0xC9,0xCC,0xCE,0xD1,0xD3,0xD5,0xD8,
  0xDA,0xDC,0xDE,0xE0,0xE2,0xE4,0xE6,0xE8,0xEA,0xEB,0xED,0xEF,0xF0,0xF2,0xF3,0xF4,
  0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFB,0xFC,0xFD,0xFD,0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFD,0xFD,0xFC,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,
  0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEB,0xE9,0xE7,0xE5,0xE3,0xE1,0xDF,0xDD,0xDB,
  0xD9,0xD7,0xD4,0xD2,0xCF,0xCD,0xCA,0xC8,0xC5,0xC3,0xC0,0xBD,0xBA,0xB8,0xB5,0xB2,
  0xAF,0xAC,0xA9,0xA6,0xA3,0xA0,0x9D,0x9A,0x97,0x94,0x91,0x8E,0x8A,0x87,0x84,0x81,
  0x7E,0x7B,0x78,0x75,0x71,0x6E,0x6B,0x68,0x65,0x62,0x5F,0x5C,0x59,0x56,0x53,0x50,
  0x4D,0x4A,0x47,0x45,0x42,0x3F,0x3C,0x3A,0x37,0x35,0x32,0x30,0x2D,0x2B,0x28,0x26,
  0x24,0x22,0x20,0x1E,0x1C,0x1A,0x18,0x16,0x14,0x13,0x11,0x10,0x0E,0x0D,0x0B,0x0A,
  0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x03,0x02,0x02,0x01,0x01,0x00,0x00,0x00,0x00,
  0x00,0x00,0x00,0x01,0x01,0x01,0x02,0x02,0x03,0x04,0x04,0x05,0x06,0x07,0x08,0x09,
  0x0B,0x0C,0x0D,0x0F,0x10,0x12,0x14,0x15,0x17,0x19,0x1B,0x1D,0x1F,0x21,0x23,0x25,
  0x27,0x2A,0x2C,0x2E,0x31,0x33,0x36,0x38,0x3B,0x3E,0x40,0x43,0x46,0x49,0x4C,0x4F,
  0x51,0x54,0x57,0x5A,0x5D,0x60,0x63,0x67,0x6A,0x6D,0x70,0x73,0x76,0x79,0x7C,0x80 };
 
 
void output_dac_sin(void)
{
  while(1) // Continous
  {
    int i;
 
    for(i=0; i<sizeof(SinLUT); i++)
    {
      HAL_StatusTypeDef status = HAL_I2C_Mem_Write(&I2CHandle, DAC_ADDR, DAC_CHANNEL, I2C_MEMADD_SIZE_8BIT, (void *)&SinLUT[i], 1, 100);
 
      if (status != HAL_OK) puts("Argh!");
    }
  }
} // sourcer32@gmail.com

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

First test that your device responds. If not, use a logic analyzer.

HAL_StatusTypeDef st;
 
#define MAX_ADDR_WRITE (0x2C << 1)
#define MAX_ADDR_READ (MAX_ADDR_WRITE | 1)
 
st  = HAL_I2C_IsDeviceReady(&hi2cX, MAX_ADDR_READ , 1 /*Trials*/, 20 /*Timeout*/);

Myilm.1
Associate II

Thank you @Community member​ .

Works great, But But the frequency is around 33hz. I guess I can't go beyond this value due to the i2c speed? it's set to 400khz.