- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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]);
}
Solved! Go to Solution.
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would use this device to interface DS2482-800 8 channel temp controller $3.98. Here is the data sheet.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.