- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm currently trying to interface accelerometer LIS3DH to the PSoC4 BLE. I selected spi master full duplex mode in PSoC creator.Can someone please tell me whether it's the correct one. And what's the difference between the normal mode and SCB mode?
Also, the registers of the accelerometer are to be configured by writing values into them. So do I have to write my own function for writing into registers or are there already some APIs in the creator.
I'm also confused about the HSIOM mentioned in the datasheet.Are we supposed to configure those registers?
Finally, pin assignments in '.cydwr' file are different than those given in the datasheet.
(e.g:
in the datasheet: MOSI=P0.0, MISO=P0.1, SCLK=P0.3 and
in the .cydwr file: MOSI=P0.0, MISO=P0.2, SCLK=P0.1)
Would I have to change the pin assignment in cydwr file?
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I wasn't quite clear. Trust the fitter in the .cydwr file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum!
Finally, pin assignments in '.cydwr' file are different than those given in the datasheet.
Which datasheet are you referring to? (Link)
I could not find a reference to P0.0. Best is to assign the pins at your needs and PSoCs capabilities.
So do I have to write my own function for writing into registers
Yes, SPI devices are quite different, so there is no general API possible.
I'm also confused about the HSIOM mentioned in the datasheet.Are we supposed to configure those registers?
No, for standard usage not required.
And what's the difference between the normal mode and SCB mode?
There are Serial Control Blocks (SCBs) from which (internally) the SPI is built. Additionally there are Universal Digital Blocks (UDBs) from which an SPI interface can be build as well. UDBs are quite more versatile, so best practice is to save them as long as possible.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot Mr. Marlowe for your help. Here's the link to the datasheet I referred (page number 14-15).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now I see. Trust the pin assignments. In the datasheet some alternatives are listed which the fitter in creator will care for.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok. So should I trust the assignments from the datasheet or the .cydwr file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, I wasn't quite clear. Trust the fitter in the .cydwr file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok.Thank you again for your time, Mr. Marlowe.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not sure if it would be of any use but I have the LIS3DH working on the I2S bus on a PRoC chip. The cypress example remote control code base was a great example for doing this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ok..i will surely give a look at that. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm still having difficulty in running my spi code.I selected the SPI master full duplex macro component.What does the component indicate-the mode in which PSoC is going to operate(master) or the mode in which accelerometer is going to operate(slave)? So accordingly should I select SPI slave full duplex macro component if it's the latter one? Also I'm confused about which function serves the purpose of writing/reading across SPI; is it SPI_WriteTxData/ SPI_ReadRxData or MOSI_Write/MISO_Read?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Master configuration is right. MOSI_Write() would try to access the pin directly which will not work because there is a direct signal connection. There is a (bit lengthy) list of APIs in the SPI datasheet. You should wait until all bytes are transferred (sent) before you access the received data. Set the internal buffers large enough to keep a transaction.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've been trying for a while to get SPI worked.But I'm still having difficulties in it. So side by side I've started working on I2C protocol (LIS3DH supports that too).I'm facing some problems there too. I'm using uart to test the code.So I added 'put string' statements at various points in I2CMasterSendStart function so as to track the error.It's showing the bus error, which according to the datasheet, is due to the misplaced start and stop conditions and because of that it's not returning the error status and blocking the further steps of main code.
Attached herewith is the workspace of the same.In the code, 0x33 is the address of the accelerometer and 0x0f is the sub address that is to be read(identity register, which has the value 0x33). Code is not working. What could possibly be wrong?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Byte I2C interface is quite simple: After setting up the component and starting it you use
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWrite(Register); // Indicate which register you want to write to
I2C_MasterWriteByte(Value); // Write to register
I2C_MasterSendStop(); // End of transaction
When you want to read from a device you use (example for reading two bytes
I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE); // Initialize a transaction for writing
I2C_MasterWrite(Register); // Indicate which register you want to write to
I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
I2C_MasterReadByte(I2C_ACK_DATA); // Read from register
I2C_MasterReadByte(I2C_NAK_DATA); // Read from register, last byte is NAKed
I2C_MasterSendStop(); // End of transaction
Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for the help.I'm confused about few more things- What exactly are the values of I2C_ACK_DATA and I2C_NAK_DATA.
I can't find them defined in any of the generated files.
Also, do I2C_MasterWrite() and I2C_MasterWriteByte() functions mean the same? Because I'm not able to find MasterWrite() function separately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Search for the names in the .h files, it is essential to use them or the equivalents when using an I2C component based on SCB.
Open the component datasheet and search for "NAK" to get the basic name.
Do not forget that your component name is "I2C_1" and not "I2C" as in my explanation.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yes, I'm extremely sorry that I didn't search properly. I made the changes you suggested.Can the function' I2C_MasterWriteByte ()' be used for sending the register address? I'm still not getting any output. It's still showing the 'bus error'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Post your actual project. Which board do you use?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content