- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi,
Could somebody explain why this SPI transfer creates a 'segmentation fault (core dumped)' error when running on the Joule?
Thanks
# include "mraa.hpp"
# include
# include
int main(int argc, char** argv) {
mraa_spi_context spi;
spi = mraa_spi_init(0);
printf("Hello, SPI initialised\n");
uint8_t data[] = { 0x00, 100 };
uint8_t* recv;
while (1) {
int i;
for (i = 90; i < 130; i++) {
data[1] = i;
recv = mraa_spi_write_buf(spi, data, 2);
printf("Writing -%i", i);
printf("RECIVED-%i-%i\n", recv[0], recv[1]);
usleep(100000);
}
}
}
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Check the following:
- The function call "mraa_spi_write_buf()" will return a NULL pointer in cases of error. Check if (recv == NULL)
- Also the pointer return has to be free'd by the caller.
To simplify, I would recommend you not loop on this at first, and just do one instruction and make sure that passes successfully:
recv = mraa_spi_write_buf(spi, data, 2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor100,
Thanks for your interest in the Intel Joule Platform.
The error "segmentation fault (core dumped)" is when a program attempts to access a memory location that it is not allowed to access, also it can be due to an infinite loop.
That said I would follow floydg advice to check your pointers and try not to use a loop in your code. Please let me know your results.
I will be waiting for your reply, have a nice day!
Best Regards,
-Jose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Also I did not see the following in your code to initialize mraa "mraa_init()":
If this is the case the spi pointer is NULL, and should be tested, before being used.
1
mraa_result_t rv;
2
rv = mraa_init();
3
if
(rv != MRAA_SUCCESS)
4
<code class="plain" style="font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !import...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thanks folks, I'll try your suggestions. Just to note that this code was just copy/pasted from the MRAA spi webpage:
https://iotdk.intel.com/docs/master/mraa/classmraa_1_1_spi.html https://iotdk.intel.com/docs/master/mraa/classmraa_1_1_spi.html
Also @floydg - are you sure 'mraa_init()' is required? It isn't called the the basic blink led example?
Conor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor100,
Did you already try to compile using the whole example code?
Please let me know, have a nice day!
Best Regards,
-Jose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
mraa_init() provides the following, and may aid with your issue in the scenario where initialization has failed:
Detects running platform and attempts to use included pinmap, this is run on module/library init/load but is handy to rerun to check board initialised correctly. MRAA_SUCCESS inidicates correct (first time) initialisation whilst MRAA_ERROR_PLATFORM_ALREADY_INITIALISED indicates the board is already initialised correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
What version of MRAA version are you running?
I think I remember having some issues with SPI on versions prior to Version v1.5.1? if you haven't already, consider upgrading.
curl https://raw.githubusercontent.com/intel-iot-devkit/joule-code-samples/master/mraa-install.sh | sh
-J
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
suggestion - first verify your version:
$ mraa-gpio version
Version v1.5.1 on Intel GT Tuchuck
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi there,
I can confirm that I'm running Version v1.5.1 on Intel GT Tuchuck and Mraa is initializing correctly. I can toggle the LEDs.
When I run the code below it writes the data to sdout and I assumed it would be writing data on the SPI_0_MOSI which is Pin 27 on J13. However, when I connect a logic analyser to P27 on J13, I see no activity.
Is this the correct way to initialize SPI 0 and write data on MOSI.
Thank you
mraa_spi_context spi;
spi = mraa_spi_init(0);
printf("Hello, SPI initialised\n");
uint8_t data[] = { 0x00, 100 };
while (1) {
int i;
for (i = 90; i < 130; i++) {
data[1] = i;
recv = mraa_spi_write_buf(spi, data, 2);
printf("Writing -%i", i);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor100,
Are you sure you are checking the right pin, looking at the datasheet, I don't see a Pin 27 assigned to a SPI input or output.
Joule datasheet: http://www.intel.com/content/dam/support/us/en/documents/joule-products/intel-joule-module-datasheet... http://www.intel.com/content/dam/support/us/en/documents/joule-products/intel-joule-module-datasheet... .
I hope this works, please let me know your results.
Have a nice day!
Best Regards,
-Jose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi Jose,
On the expansion board connector pin 27 on J13 is listed listed as SPI_0_MOSI?
http://www.intel.com/content/www/us/en/support/boards-and-kits/intel-joule-kits/000022494.html http://www.intel.com/content/www/us/en/support/boards-and-kits/intel-joule-kits/000022494.html
I would of expected initializing SPI_0 would send data out on this pin?
Thanks
Conor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi Jose,
I cannot figure out why the code below will not write data out on the expansion board connector pin 27 on J13.
I have pin 27 (J13) connected to pin pin 29 (J13). 'mraa_spi_write_buff' returns a null pointer.
Am I doing something obviously wrong? Would you mind testing please?
Many thanks
# include "mraa.h"
# include
# include
int main(int argc, char **argv) {
mraa_init();
mraa_spi_context spi;
spi = mraa_spi_init(0);
printf("SPI initialised\n");
uint8_t data[] = {0x56, 0x00, 0x26, 0x00};
uint8_t *recv;
recv = mraa_spi_write_buf(spi, data, 4);
printf("Writing Data on SPI_0 MOSI 0x%X + 0x%X + 0x%X + 0x%X\n", data[0], data[1], data[2], data[3]);
if (recv == NULL) {
printf("Errors encountered when writing1\n");
}
else {
printf("RECEIVED 0x%X + 0x%X + 0x%X + 0x%X + 0x%X\n",recv[0], recv[1], recv[2], recv[3], recv[4]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor999,
Could you be so kind to try this code:
# include "mraa.h"
# include
# include
int main()
{
mraa_init();
mraa_spi_context spi=mraa_spi_init(0);
mraa_spi_frequency (spi, 400000);
mraa_spi_mode(spi,MRAA_SPI_MODE0);
mraa_spi_lsbmode(spi,0);
mraa_spi_bit_per_word(spi,8);
uint16_t read_data = mraa_spi_write(spi,0xAA);
mraa_spi_stop(spi);
return MRAA_SUCCESS;
}
Please let me know if you still can't see anything in your logic analyzer.
Also I will test your code to see if I have the same issues as you.
Have a nice day!
Best Regards,
-Jose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi Jose,
I tested your code and I still see no activity on the logic analyzer. I am testing pin 27 on connector J13.
What were the results of my code?
Thanks
Conor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor100,
I appreciate your patience. I have tested your example and the other two samples of SPI, one in python and the other in C. The three codes compiled successfully, I attached you the images below:
SPI of Conor100:
SPI in Python (https://github.com/intel-iot-devkit/mraa/blob/master/examples/python/spi.py mraa/spi.py at master · intel-iot-devkit/mraa · GitHub ):
SPI in C (That I provided in my previous reply):
Doing the tests, I noticed that mraa depending on the SPI interface that you selected. It assigns a set of pins, for example:
Bus 0 MOSI = 2 MISO = 4 CS = 6 CLK = 10
Bus 1 MOSI = 67 MISO = 69 CS0 = 59 CS1 = 61 CLK = 65
In the three codes above, we selected Bus 0: "mraa_spi_context spi=mraa_spi_init(0);". Looking at the pinout distribution in http://www.intel.com/content/www/us/en/support/boards-and-kits/intel-joule-kits/000022494.html Intel® Joule™ Expansion Board Breakout Definition for Linux* the pins 2, 4, 6 and 10; are in the Breakout 12 (J12).
Could you please test any of the codes above and check the signals in J12? Please let me know your results.
Have a nice day!
Best Regards,
-Jose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi Jose,
Can you confirm that your OS is Ubuntu 16.04 LTS and not Ostro. I have tried your c and python examples. Both examples return NULL on 'mraa_spi_init(0)' and there is no activity on the pins. Has Mraa SPI been tested on Ubuntu 16.04?
The GPIOs work OK so there is no issue with my mraa installation.
Also you have reversed the MOSI and MISO pin numbers in your previous post. It should read:
Bus 0 MOSI = 4 MISO = 2 CS = 6 CLK = 10
Update: I can confirm that SPI works on Ostro. The same code does not work on Ubuntu.
Thanks
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor100,
Thanks for the correction, now regarding if Mraa has been tested in Ubuntu 16.04,
unfortunately the scooped of our support is limited to the Ostro OS.
I will encourage you to contact the Ubuntu Community, maybe they will be able to assist you.
Ubuntu Community: https://developer.ubuntu.com/core/get-started/intel-joule Intel Joule | Developer
Have a nice day!
Best Regards,
-Jose.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Hi conor100,
Do you have any more questions? Please let me know in order to assist you.
I will be waiting for your reply, have a nice day!
Best Regards,
-Jose P.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page