I2C communication between PSOC 5LP and Attiny85

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi, I'm new here.

   

I'm trying to establish I2C communication between my PSOC 5LP (as master) and one attiny85 (as slave) that is sending one float. I programmed attiny with arduino (library TinyWireS.h) and I want to know if it is possible to read the value via PSOC.

   

Master code:

   


#include <project.h>
#define SLAVE_ADDR 0x26
union v{
    float val;
    char8 data[5];
} temp;
volatile uint8 status;
uint8 i;
int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
   
    LCD_Start();
    LCD_Position(0,1);
    LCD_PrintString("Temp: ");
   
    I2C_1_Start();
         
    status = I2C_1_MasterSendStart(SLAVE_ADDR, I2C_1_READ_XFER_MODE);
   
    if (status == I2C_1_MSTR_NO_ERROR){
        CyDelay(1);
        for (i=0; i<5; i++){
            if(i < 4) {
                temp.data = I2C_1_MasterReadByte(I2C_1_ACK_DATA);
            }
           
            else temp.data = I2C_1_MasterReadByte(I2C_1_NAK_DATA);
       
        }
        LCD_Position(1,1);
        LCD_PrintNumber(temp.val);
    }
   
    I2C_1_MasterSendStop();
    I2C_1_MasterClearReadBuf();
    
}
 

   

slave code:

   


#include <TinyWireS.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define SLAVE_ADDR 0x26
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup()
{
  sensors.begin();
  TinyWireS.begin(SLAVE_ADDR);
  TinyWireS.onRequest(requestEvent);
}
union v{
  float val;
  unsigned char data[4];
} t1, t2;
void loop()
{
}
void requestEvent()
{
  //sensors.requestTemperatures();
  t1.val = 123.45;
  TinyWireS.send (t1.data[reg_position]);
   
}
 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I would use this device to interface  DS2482-800 8 channel temp controller $3.98.  Here is the data sheet. 

View solution in original post

0 Likes
4 Replies
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Check out this program it works with the Dallas one wire temp device.

0 Likes
Anonymous
Not applicable

I already saw that example but I cannot read temperature from multiple sensors in the same wire. My idea using attiny is read at least five sensors ds18b20, which I already did with arduino, and receive all values in PSOC.

   

I wish someone could help me. 

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

I would use this device to interface  DS2482-800 8 channel temp controller $3.98.  Here is the data sheet. 

0 Likes
Anonymous
Not applicable

Thank you for your help bobgoar, I solved my problem. 

   

Now I can stablish connection between attiny and PSoC, I had to change the way I was reading data. 

0 Likes