Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

chip select problem in SPI communication..!!!

Status
Not open for further replies.

hussain_kiet

Full Member level 5
Joined
Mar 15, 2007
Messages
260
Helped
45
Reputation
90
Reaction score
28
Trophy points
1,308
Location
Karachi, Pakistan
Activity points
2,802
I have a problem with chip select(CS) pin of BMA180....Initially I set CS high, SCK high, and MOSI high....Then I start reading chip ID and it returns 03h which is ok but after sometime the voltage on CS pin drops to 1V and data is corrupted....I have used voltage divider of (560 ohms and 1k) on CS,SCK and MOSI pins as BMA180 is not 5V tolerant.

I have also tested it with transistor for CS with collector pulled up with 1k resistor to 3.3V but the problem remained.

Why is voltage dropped on CS pin only and it is Ok for SCK and MOSI pins which remains at 3.2V level??

CS pin is internally pulled up on BMA180 and I am using SPI interface.

Thanks
 

BMA180 is 3.3v device. You should use a level translator to do this and not just a potential divider. Try mosfet level translator or IC level translator

You must understand that output from BMA180 will be at 3.3v...How could it be interfaced with a 5v MCU?
 

I have solved that problem....actually I removed the voltage divider and used transistor with collector directly connected to CS of BMA180 as it is internally pulled up....

I am facing another problem now......

I have successfully read acceleration data registers of all three axis but I can't write to any register......Actually I want to change my bandwidth and range

The code for writing is given below:

int init_BMA180(uint8_t range, uint8_t bw)
{
char temp, temp1;

// if connected correctly, ID register should be 3
CS_LOW;
if(read(ID) != 3)
{
CS_HIGH;
return -1;
}

//-------------------------------------------------------------------------------------
// Set ee_w bit
CS_LOW
temp = read(CTRLREG0);
CS_HIGH;
temp |= 0x10;
write(CTRLREG0, temp); // Have to set ee_w to write any other registers

//-------------------------------------------------------------------------------------

// Disable I2C
CS_LOW;
temp = read(0x27);
CS_HIGH;
temp1 = 0x01;
temp |= temp1;
write(0x27, temp);

//-------------------------------------------------------------------------------------
// Set BW
CS_LOW;
temp = read(BWTCS);
CS_HIGH;
temp1 = bw;
temp1 = temp1<<4;
temp &= (~BWMASK);
temp |= temp1;
write(BWTCS, temp); // Keep tcs<3:0> in BWTCS, but write new BW

//-------------------------------------------------------------------------------------

// Set Range
CS_LOW;
temp = read(OLSB1);
CS_HIGH;
TxByte(temp);
temp1 = range;
temp1 = (temp1<<RANGESHIFT);
temp &= (~RANGEMASK);
temp |= temp1;
write(OLSB1, temp); //Write new range data, keep other bits the same
}


void write(uint8_t address, char data)
{
address &= 0x7F;

CS_LOW;
_delay_ms(10);
txdata(address);
_delay_ms(10);
txdata(data);
_delay_ms(10);
CS_HIGH;
}

char read(uint8_t address)
{
char byte;

address |= 0x80;

SCK_ACC_HIGH;

//CS_HIGH;

txdata(address);
byte = rxdata();

//CS_LOW;

return byte;
}

char rxdata(void)
{
char recv,i;
recv=0;

for(i=0; i<8; i++)
{
recv<<=1;

SCK_ACC_LOW;

_delay_us(1);

SCK_ACC_HIGH;

if((PINC & (1<<4)))
recv |= 0x01;
}

return recv;
}

void txdata(char data)
{
char i;

for(i=0; i<8; i++)
{
if((data & 0x80) == 0x80)
{MOSI_ACC_HIGH;}
else
{MOSI_ACC_LOW;}

SCK_ACC_LOW;

_delay_us(1);

data<<=1;

SCK_ACC_HIGH;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top