Cortex ve I2C

Başlatan muhittin_kaplan, 02 Temmuz 2013, 22:41:39

muhittin_kaplan

Çalışmış olan varmı Tecrübeleriniz Nedir ?
STM32F1xx yafa F4 ile örneğin

X-Fi

Hocam soruyu tam olarak anlamadım ama stdperipheral kütüpanelerini kullanıyorum, eeprom okuyup yazmak için. 4.7K ile External pull-up yapmalısınız internal pull-uplar temiz bir hat için yeterli gelmeyebilir.
http://www.coskunergan.dev/    (Yürümekle varılmaz, lakin varanlar yürüyenlerdir.)

muhittin_kaplan

Soruda birşeyok hocam I2C standart ktüphane ile kullanmak istiyorum. Şu elimde yeni geçen mpu6050 için. Yazılmış kütüphane buldum ama anlamak irdelemek istiyorum.


muhittin_kaplan

#4
Çalıştığını Cihaz Olmadan Kontrol Edebilirmiyim. Yani İStediğim Adresi Datayı Yolladığımı vs yi Nasıl Kontrol Ederim. Saleae Logic Analyzer mevcut
(Mod Arkadaşlar Konuyu Birleştirirse Sevinirim. MP6050 Hazırlık Yapalım Konusuyla)

mesaj birleştirme:: 04 Temmuz 2013, 01:32:56

Yoruldum, Yapamadım. YArın Devam

CoşkuN

Alıntı yapılan: muhittin_kaplan - 04 Temmuz 2013, 00:59:23
Çalıştığını Cihaz Olmadan Kontrol Edebilirmiyim. Yani İStediğim Adresi Datayı Yolladığımı vs yi Nasıl Kontrol Ederim. Saleae Logic Analyzer mevcut
(Mod Arkadaşlar Konuyu Birleştirirse Sevinirim. MP6050 Hazırlık Yapalım Konusuyla)

mesaj birleştirme:: 04 Temmuz 2013, 01:32:56

Yoruldum, Yapamadım. YArın Devam

Hocam sensör gelene kadar i2c eeprom felan çalıştırarak deneme yapabilirsin belki.

muhittin_kaplan

#6
Sensör geldi  8)

mesaj birleştirme:: 04 Temmuz 2013, 11:51:01

Hocam Olay Sönsör değil, Hiçbirşey gönderemiyorum, Start Yapamıyorum, I2C yi STM ile kullanmadım şu ana kadar.

mesaj birleştirme:: 04 Temmuz 2013, 12:31:41

f4 ile çalışıyorum bu arada


M_B

hocam
Stm32f407 Discovery kitle  LM75 uygulamasında kullandığım kod.
Kod çalışıyor
Kodu incelerken LM75 Datahseet incelemek gerekebilir.  Mantığını anlamak icin.


tsensor.c
/* Includes ------------------------------------------------------------------*/
#include "tsensor.h"
#include "stm32f4xx_i2c.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stdio.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define LM75_Addr      0x90 /* LM75 address */
#define LM75_SD_Set    0x01 /* Set SD bit in the configuration register */
#define LM75_SD_Reset  0xFE /* Reset SD bit in the configuration register */

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
static u8    TempCelsius_Display[] = "     +abc.def C     ";
static u8 TempFahrenheit_Display[] = "     +abc.def F     ";
 u32 Temp_Decimal = 0, TempCelsius_Value = 0, Temp_Value_Fahrenheit = 0;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : I2C_LM75_Init
* Description    : Initializes the I2C1.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_LM75_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
  I2C_InitTypeDef   I2C_InitStructure;

  // GPIOB Periph clock enable //
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
  // I2C1 Periph clock enable //
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1 , ENABLE);
    
  // Configure I2C1 pins: SCL and SDA //
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_8 | GPIO_Pin_7; // PB8=SCL , PB7=SDA
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_OType=GPIO_OType_OD;
    GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_I2C1);  
  GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
    
   //Configure PB.5 as Input pull-up, used as TemperatureSensor_INT //
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  I2C_DeInit(I2C1);
    
 
    // I2C1 Init //
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; 
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = 0x00;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = 100000;
  I2C_Init(I2C1, &I2C_InitStructure);
    
      // I2C1 Init //
    I2C_Cmd(I2C1, ENABLE);
}

/*******************************************************************************
* Function Name  : I2C_LM75_Status
* Description    : Checks the LM75 status.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
ErrorStatus I2C_LM75_Status(void)
{
  u32 I2C_TimeOut = 0x3FFFF;

  /* Clear the I2C1 AF flag */
  I2C_ClearFlag(I2C1, I2C_FLAG_AF);

  /* Enable I2C1 acknowledgement if it is already disabled by other function */
  I2C_AcknowledgeConfig(I2C1, ENABLE);

  /*----- Transmission Phase -----*/
  
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  while((!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) && I2C_TimeOut)/* EV6 */
  {
    I2C_TimeOut--;
  }

  if(I2C_GetFlagStatus(I2C1, I2C_FLAG_AF) != 0x0)
  {
    return ERROR;
  }
  else
  {
    return SUCCESS;
  }
}

/*******************************************************************************
* Function Name  : I2C_LM75_Reg_Read
* Description    : Read the specified register from the LM75.
* Input          : RegValue: this member specifies the register to read:
*                    - LM75_TEMP_Reg: temperature register
*                    - LM75_TOS_Reg: Over-limit temperature register
*                    - LM75_THYS_Reg: Hysteresis temperature register
* Output         : None
* Return         : None
*******************************************************************************/
u16 I2C_LM75_Reg_Read(u8 RegName)
{
  u32 RegValue=0;

  /* Enable I2C1 acknowledgement if it is already disabled by other function */
  I2C_AcknowledgeConfig(I2C1, ENABLE);

  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }

  /* Send the specified register data pointer */
  I2C_SendData(I2C1, RegName);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /*----- Reception Phase -----*/
  /* Send Re-STRAT condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for read */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Receiver);
  
  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))  /* EV6 */
  {
  }
  

  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  /* EV7 */
  {
  }
  
  /* Store I2C1 received data */
  RegValue = (u16)(I2C_ReceiveData(I2C1) << 8);
  
  /* Disable I2C1 acknowledgement */
  I2C_AcknowledgeConfig(I2C1, DISABLE);
  
  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
  
  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  /* EV7 */
  {
  }
  
  /* Store I2C1 received data */
  RegValue |= I2C_ReceiveData(I2C1);

  /* Return register value */
  return (RegValue >> 7);
}

/*******************************************************************************
* Function Name  : I2C_LM75_Reg_Write
* Description    : Write to the specified register of the LM75.
* Input          : RegValue: this member specifies the register to read:
*                    - LM75_TEMP_Reg: temperature register
*                    - LM75_TOS_Reg: Over-limit temperature register
*                    - LM75_THYS_Reg: Hysteresis temperature register
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_LM75_Reg_Write(u8 RegName, u16 RegValue)
{
  /* Shift left register value */
  RegValue = RegValue << 7;

  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }

  /* Send the specified register data pointer */
  I2C_SendData(I2C1, RegName);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /* Send I2C1 data */
  I2C_SendData(I2C1, (u8)(RegValue >> 8));
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }
  
  /* Send I2C1 data */
  I2C_SendData(I2C1, (u8)RegValue);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);    
}

/*******************************************************************************
* Function Name  : I2C_LM75_Temp_Read
* Description    : Read Temperature register of LM75: double temperature value.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
u16 I2C_LM75_Temp_Read(void)
{
  u32 RegValue = 0;

  /* Enable I2C1 acknowledgement if it is already disabled by other function */
  I2C_AcknowledgeConfig(I2C1, ENABLE);

  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }

  /* Send the temperature register data pointer */
  I2C_SendData(I2C1, LM75_TEMP_Reg);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /*----- Reception Phase -----*/
  /* Send Re-STRAT condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for read */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Receiver);
  
  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))  /* EV6 */
  {
  }

  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  /* EV7 */
  {
  }
  
  /* Store I2C1 received data */
  RegValue = I2C_ReceiveData(I2C1) << 8;
  
  /* Disable I2C1 acknowledgement */
  I2C_AcknowledgeConfig(I2C1, DISABLE);
  
  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
  
  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  /* EV7 */
  {
  }
  
  /* Store I2C1 received data */
  RegValue |= I2C_ReceiveData(I2C1);

  /* Return Temperature value */
  return (RegValue >> 5);
}

/*******************************************************************************
* Function Name  : I2C_LM75_ConfReg_Read
* Description    : Read the configuration register from the LM75.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
u8 I2C_LM75_ConfReg_Read(void)
{
  u32 RegValue = 0;

  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }

  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }

  /* Send the configuration register data pointer */
  I2C_SendData(I2C1, LM75_CONF_Reg);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /*----- Reception Phase -----*/
  /* Send Re-STRAT condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for read */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Receiver);
  
  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))  /* EV6 */
  {
  }

  /* Disable I2C1 acknowledgement */
  I2C_AcknowledgeConfig(I2C1, DISABLE);
  
  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);

  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  /* EV7 */
  {
  }
  
  /* Store I2C1 received data */
  RegValue = I2C_ReceiveData(I2C1);

  /* Return configuration register value */
  return (RegValue);    
}

/*******************************************************************************
* Function Name  : I2C_LM75_ConfReg_Write
* Description    : Write to the configuration register of the LM75.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_LM75_ConfReg_Write(u8 RegValue)
{
  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);

  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }

  /* Send the configuration register data pointer */
  I2C_SendData(I2C1, LM75_CONF_Reg);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /* Send I2C1 data */
  I2C_SendData(I2C1, RegValue);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);     
}

/*******************************************************************************
* Function Name  : I2C_LM75_ShutDown
* Description    : Enables or disables the LM75.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_LM75_ShutDown(FunctionalState NewState)
{
  u32 RegValue = 0;

  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }

  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }

  /* Send the configuration register data pointer */
  I2C_SendData(I2C1, LM75_CONF_Reg);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))  /* EV8 */
  {
  }

  /*----- Reception Phase -----*/
  /* Send Re-STRAT condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for read */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Receiver);
  
  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))  /* EV6 */
  {
  }
  
  /* Disable I2C1 acknowledgement */
  I2C_AcknowledgeConfig(I2C1, DISABLE);
  
  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);

  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))  /* EV7 */
  {
  }
  
  /* Store I2C1 received data */
  RegValue = I2C_ReceiveData(I2C1);

  /*----- Transmission Phase -----*/
  /* Send I2C1 START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on I2C1 EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))  /* EV5 */
  {
  }
  
  /* Send STLM75 slave address for write */
  I2C_Send7bitAddress(I2C1, LM75_Addr, I2C_Direction_Transmitter);
  
  /* Test on I2C1 EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) /* EV6 */
  {
  }
  
  /* Send the configuration register data pointer */
  I2C_SendData(I2C1, LM75_CONF_Reg);
  
  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /* Enable or disable SD bit */
  if (NewState != DISABLE)
  {
    /* Disable LM75 */
    I2C_SendData(I2C1, RegValue | LM75_SD_Set);
  }
  else
  {
    /* Enable LM75 */
    I2C_SendData(I2C1, RegValue & LM75_SD_Reset);
  }

  /* Test on I2C1 EV8 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) /* EV8 */
  {
  }

  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);     
}

/*******************************************************************************
* Function Name  : Thermometer_Temperature
* Description    : Displays the temperature in Celsius and fahrenheit degree.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void Thermometer_Temperature(char buffer1[], char buffer2[])
{
  int i;
  if(I2C_LM75_Status() == SUCCESS)
  {
   TempCelsius_Value = I2C_LM75_Temp_Read();
   }
  if(TempCelsius_Value <= 1023)
      {
        /* Positive temperature measured */
        TempCelsius_Display[5] = '+';
        TempFahrenheit_Display[5] = '+'; 
      }
      else
      {
        /* Negative temperature measured */
        TempCelsius_Display[5] = '-'; 
        TempFahrenheit_Display[5] = '-'; 
        /* Remove temperature value sign */
        TempCelsius_Value = 0x800 - TempCelsius_Value;
     }

      /* Calculate temperature digits in °C */
      Temp_Decimal = ((TempCelsius_Value & 7) * 1000 / 8);
      TempCelsius_Display[10] = (Temp_Decimal / 100) + 0x30;
      TempCelsius_Display[11] = ((Temp_Decimal % 100) / 10) + 0x30;
      TempCelsius_Display[12] = ((Temp_Decimal % 100) % 10) + 0x30;
      TempCelsius_Value >>= 3;
      TempCelsius_Display[6] = (TempCelsius_Value / 100) + 0x30;
      TempCelsius_Display[7] = ((TempCelsius_Value % 100) / 10) + 0x30;
      TempCelsius_Display[8] = ((TempCelsius_Value % 100) % 10) + 0x30;

      /* Convert temperature °C to Fahrenheit */
      Temp_Value_Fahrenheit = ((9 * ((TempCelsius_Value * 1000) + Temp_Decimal)) / 5) + 32000;

      /* Calculate temperature digits in °F */
      TempFahrenheit_Display[6] = (Temp_Value_Fahrenheit / 100000) + 0x30;
      TempFahrenheit_Display[7] = ((Temp_Value_Fahrenheit % 100000) /10000) + 0x30;
      TempFahrenheit_Display[8] = ((Temp_Value_Fahrenheit % 100000) %10000/1000) + 0x30;
      TempFahrenheit_Display[10] = ((((Temp_Value_Fahrenheit % 100000) %10000) %1000) /100) + 0x30;
      TempFahrenheit_Display[11] = (((((Temp_Value_Fahrenheit % 100000) %10000) %1000) %100) /10) + 0x30;
      TempFahrenheit_Display[12] = (((((Temp_Value_Fahrenheit % 100000) %10000) %1000) %100) %10) + 0x30;

      /* Display Fahrenheit value on LCD */
      for (i = 0; i < 14; i++)
      {
        buffer1[i] = TempCelsius_Display[i];
        buffer2[i] = TempFahrenheit_Display[i];
      }
	  	buffer1[13] = ' ';
	    buffer1[14] = 'C';

		buffer2[13] = ' ';
	    buffer2[14] = 'F';

		buffer1[15] = '\0';
     	buffer2[15] = '\0';

    /*
	  buffer1[i] = ' ';
      buffer2[i++] = ' ';
      buffer1[i] = 'C';
      buffer2[i++] = 'F';
      buffer1[i] = '\0';
      buffer2[i] = '\0';
*/
  
  }


tsensor.h
/****************************************************************
* File Name          : tsensor.h
* Version            : V1.1.0
****************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TSENSOR_H
#define __TSENSOR_H

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Private define ------------------------------------------------------------*/
#define LM75_TEMP_Reg       0x00  /* Temperature Register of LM75 */
#define LM75_CONF_Reg       0x01  /* Configuration Register of LM75 */
#define LM75_THYS_Reg       0x02  /* Temperature Register of LM75 */
#define LM75_TOS_Reg        0x03  /* Over-temp Shutdown threshold Register of LM75 */

/* Exported types ------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void I2C_LM75_Init(void);
ErrorStatus I2C_LM75_Status(void);
uint16_t I2C_LM75_Temp_Read(void);
uint16_t I2C_LM75_Reg_Read(uint8_t  RegName);
void I2C_LM75_Reg_Write(uint8_t  RegName, uint16_t RegValue);
uint8_t  I2C_LM75_ConfReg_Read(void);
void I2C_LM75_ConfReg_Write(uint8_t  RegValue);
void I2C_LM75_ShutDown(FunctionalState NewState);
void Thermometer_Temperature(char buffer1[], char buffer2[]);

#endif /* __TSENSOR_H */
İmkanın sınırlarını görmek için imkansızı denemek lazım.                                                             Fatih Sultan Mehmet

CoşkuN

Alıntı yapılan: muhittin_kaplan - 04 Temmuz 2013, 11:49:27
Sensör geldi  8)

mesaj birleştirme:: 04 Temmuz 2013, 11:51:01

Hocam Olay Sönsör değil, Hiçbirşey gönderemiyorum, Start Yapamıyorum, I2C yi STM ile kullanmadım şu ana kadar.

mesaj birleştirme:: 04 Temmuz 2013, 12:31:41

f4 ile çalışıyorum bu arada

MPU'yu bağlayarak mı çalışıyorsun hocam? Pull-up dirençleri bağlı mı?

muhittin_kaplan

#10
Hocam
http://www.ebay.com/itm/261080395340?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
kiti kullanıyorum. muhtemeldir ki pullup lar bağlıdır. (baktım bağlıymış)

M_B hocanın i2c dosyalarını inceleyeceğim akşama. 

Evet discoverykit ve sensörü bağlıyor araya (çengel atarak ,paralel) logic analizer bağlıyorum. sda devamlı high, scl devamlı low da kalıyor

CoşkuN

Sorun çözüldü mü?

muhittin_kaplan

Hocam yazmadım kusra bakmayın. evet çözüldü, yakında yazarım.


muhittin_kaplan

Alıntı yapılan: X-Fi - 02 Temmuz 2013, 23:24:25
Hocam soruyu tam olarak anlamadım ama stdperipheral kütüpanelerini kullanıyorum, eeprom okuyup yazmak için. 4.7K ile External pull-up yapmalısınız internal pull-uplar temiz bir hat için yeterli gelmeyebilir.
dün elimdeki 24c256 ile deneme yapacaktım.
program kütüphanede checkevent de kalıyor. Pınler pullup olarak ayarlı olmasına rağmen çalıştıramadım. akşama harici pullUp yaparak deneyeyim.