- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello.
I saw Project #047 post and it really fun to me and helped me alot.
I'v tried "Accelerometer Controlled Car" example and it doing very well. Very fun 😄
However when I changed acceleromemter sensor from Adxl355(ADC) to Adxl362(using SPI) it didnt work.
I think my Psoc 4 ble SPI setting is wrong, bcz when I tested Adxl362 with Arduino it worked.
Anybody help, adivce or example me about using Adxl362(SPI) Accelerometer sensor with Psoc 4 BLE?
I attached Adxl362 datasheet and my project.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum!
First: Is your initial message "Start" transmitted and received without error or do you have a communications problem?
Second: Your code shows
SPIM_WriteTxData(0x00);
ss_Write(1);
//read DevID val(0xAD) //the result must get a 0xAD
uint8 rs = SPIM_ReadRxData();
You remove the ss signal before the transmission is complete
When you read the response, you did not keep in mind that every sent byte will get a (at least dummy) response. So you sent 3 bytes, you will receive 3 bytes. And you did not check before reading whether the SPIM already received your 3 bytes.
Use SPIM_ReadTxStatus() to check if transmission is complete
Use SPIM_GetRxBufferSize() to check for number of bytes that can be red-off the FIFO.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I solved my problem.
Thank bob.
Finally I change my code.
ss_Write(0);
SPIM_WriteTxData(0x0B); //read op
SPIM_WriteTxData(reg); //reg address
SPIM_WriteTxData(0x00); //dummy data
while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE)); //wait
ss_Write(1);
while(!(SPIM_GetRxBufferSize()));
uint8 rtData = SPIM_ReadRxData(); //read
The Adxl362 return just one byte data so my code receives one byte.
It works very well.
Thanks very much!!!
J.J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i tried using the code u shared but the x,y,z registers return only 0..
The snippet of the code is below:
ss_Write(0);
SPIM_WriteTxData(0x0B); //read op
SPIM_WriteTxData(0x08); //reg address
SPIM_WriteTxData(0x00); //dummy data
while(!(SPIM_ReadTxStatus() & SPIM_STS_SPI_DONE)); //wait
ss_Write(1);
while(!(SPIM_GetRxBufferSize()));
uint8 rtData = SPIM_ReadRxData(); //read
and when i tried reading the status register it returned 0xC0 instead of 0x40
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you please send me the complete ADXL362 project? I have difficulties to connect and read a valid data. I am raying to send the acceleration data over BLE link. The BLE portion is functional but SPI interface to ADXL362 is not.
Thanks,
Mahyar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Ahamed
Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- 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
After initialization using SPIMM_Start() you do not clear the receive buffer, so status will return an overflow.
the line
while(!(SPIM_GetRxBufferSize()));
immediately return because you wrote 3 bytes and waited for transmission, so now in rx buffer are 3 answered bytes.
Next you read only one byte from rx buffer and start over writing bytes...
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Bob,
i tried what @lavendy tried..i attached the code which has comments ...i initialized SPIMM_start just to start the measurement....and i recieve all the default values from the sensor ...only the x,y,z data is not being recieved,,i think there is some problem with the configuration ..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ahamed,
This is not a solution to your problem, but I have attached a zip file containing a header file and source file I made for interacting with the ADXL362 module.
The source file 'ADXL362.c' contains some functions like writing to register or reading from register. Note that this isn't a comprehensive list of functions. If you decide to use them, make sure to include both files in your project.
For example,
/* Configure Filter Control Register */
while(!SPIWriteToRegister( FILTER_CTL , RANGE_4G_BIT_MASK |
HALF_BW_1_4_BIT_MASK | ODR_100_HZ_BIT_MASK));
/* Configure Power Control Register and Enable ADXL362 In Measurement Mode */
while(!SPIWriteToRegister( POWER_CTL , NORMAL_MODE_BIT_MASK |
MEASUREMENT_MODE_BIT_MASK));
For reading accelerometer x y z 8-bit registers ...
int8 accelArr[3]; // stores local x, y & z axis data
// Read contents of x, y & z - axes registers from accel
SPIReadFromXYZ8Registers(accelArr);
My implementation makes use of an SPI component to communicate with the ADXL362 and a control register to set the slave select line (high or low). SS line is active low.
Good luck! Hope it helps!