Skip to content

CAN Interface for the Mini2440 Dev. Board

As part of the student project where I was using the Mini2440 board, I was also taking care of implementing a CAN network between a few PIC devices and that board.
Here is a very cheap yet powerful CAN interface for that board.

Logo-v10-black

While being a very cheap board, the mini2440 has also great features, but since the MCU used (Samsung S3C2440) is made for consumer products like phones or GPS, is does not implement any CAN driver.

As I needed one, I built this small card. I guess the design is really easy to understand cause, well … it’s really simple, but it might be useful to some people. Feel free to comment or modify the card, just don’t sell it.

This article is not finished, I publish it now cause I’ve been writing it for few months (since march 2009 …) and I guess there is already some interesting informations for advanced users, but this is a WIP. I will resume it and add stuff if people are interested and when I have time, and I’ll also try to answer comments the best I CAN Smile

Hardware

The board has a IO extension port of 34 pins, which make it possible to access to:

  • +5V and GND : we can power something
  • an SPI interface
  • some GPIOs

The S3C2440 feature an SPI interface, which is a slave-master bus that allow the MCU to drive peripherals.

Since I didn’t had much time to develop this, the main purpose of this card is to re-use what’s available. On linux, the socket-CAN project intend to provide a socket way to access CAN controllers. Few drivers are available, one is for Microchip MCP251x CAN drivers, which provide an SPI interface. As SPI drivers for linux are available in the kernel, and as MCP2515 drivers are provided by the socket-CAN project, I decided to use it.

The Mini2440 provide few IO ports in order to add peripherals, but they’re not standardized. On the Mini2440 schematic we can see that an SPI port is available on the 34 pins port, that’s the one I used.

The 34 pins connector is quite hard to find since it is not really a common one. I didn’t manage to find one on Farnell/RS/… : the only one I found on Farnell was a Harwin model, but really had too tiny holes, don’t order it, it won’t work. However, I did find another connector on Harwin, the M22-7141742, it’s a 2mm 34pins header which fit great with the board connector. I asked for samples on the harwin website and received it two days latter, they provide a really great service and quality products.

The CAN connector is not a standard one, in our bot we had another norm using a 10 pin header instead of an expansive DB-9.

I made the schematic and PCB under Protel DXP, cause it’s a standard in my school (hopefully not for long, we are switching to Eagle this year). I can eventually make the schematic and PCB under Eagle with a DB-9 connector if there is demand for it. I’m not yet comfortable with Eagle though, if someone can do that I would be happy to edit and add his content (and credit them of course).

Schematic:
Can2440-Schematic

PCB:
Can2440-PCB

Software

I used Embdebian and Angstrom on my board, I guess you should not have any problem using the board with another distro as long as it has a linux kernel Smile

The software part relies on 2 things:

I just heard that the mini2440 repository for the kernel has been merged into the official repository, but in order to work you just need kernel sources with Mini2440 support.

Then you will have to modify the machine definition to configure the SPI interface. As you will see, this is not very clean as we need the driver’s header to be included, and as the SocketCAN project is not part of the kernel … But well, it works.

Here is some kind of patch I made, you should be really careful and understand what happens. As the kernel is in active developmental, I can’t say that it won’t broke in a few days.
NB: All that somehow explain why I didn’t do a real patch, cause if you don’t understand why you’re copy/pasting this code, you’re going down.

arch/arm/mach-s3c2440/mach-mini2440.c

// This is ugly, but I didn't find any other clean way as socketcan is external to the kernel
#include "/path/to/socketcan/kernel/2.6/include/linux/can/platform/mcp251x.h"
 
/* SPI / CAN MCP251x support */
static void mini2440_set_cs(struct s3c2410_spi_info *spi, int cs, int pol) {
int pin;
 
switch(cs) {
case 0:
pin = S3C2410_GPG2;
break;
default:
printk("BUG in %s, wrong CS %d\n", __FUNCTION__, cs);
return;
}
 
s3c2410_gpio_setpin(pin, pol);
s3c2410_gpio_cfgpin(pin, S3C2410_GPIO_OUTPUT);
}
 
static struct s3c2410_spi_info mini2440_spi_pd = {
.num_cs         = 1,
.set_cs         = mini2440_set_cs,
};
 
int mcp251x_setup(struct spi_device *spi)
{
printk(KERN_INFO "MINI2440: Loading MCP251x setup\n");
s3c2410_gpio_pullup(S3C2410_GPG9, 0);
return 0;
}
 
static struct mcp251x_platform_data mcp251x_info __initdata = {
.oscillator_frequency = 8000000,
.board_specific_setup = &mcp251x_setup,
.model = CAN_MCP251X_MCP2515,
.power_enable = NULL,
.transceiver_enable = NULL,
};
 
static struct spi_board_info mini2440_spi_board_info[] __initdata = {
[0] = {
.modalias      = "mcp251x",
.platform_data = &mcp251x_info,
.irq           = IRQ_EINT17, /* GPG9 */
.max_speed_hz  = 2*1000*1000,
.chip_select   = 0,
.bus_num       = 0,
.mode          = 0
},
};
 
...
 
static struct platform_device *mini2440_devices[] __initdata = {
...,
&s3c_device_iis,
&mini2440_audio,
&s3c_device_spi0
};
 
static void __init mini2440_init(void)
{
...
 
/* turn LCD on */
s3c2410_gpio_cfgpin(S3C2410_GPC0, S3C2410_GPC0_LEND);
 
/* Init SPI */
s3c_device_spi0.dev.platform_data = &mini2440_spi_pd;
i = spi_register_board_info(mini2440_spi_board_info, ARRAY_SIZE(mini2440_spi_board_info));
printk(KERN_INFO "MINI2440: SPI p_d set %i\n", i);
 
...
}

In order to compile the kernel, you must have a SocketCAN repo somewhere on your host computer. You must change the path of the include line to a valid mcp251x header.
Then after preparing your kernel for your board as usual, you should install SocketCAN.

I’m not gonna enter in the details to make this piece of board, there is plenty of information on the Internet that explain how to make PCBs if you don’t already know.
Check carefully that there is no short circuit or anything though, it won’t do any good to your mini2440.

Ok so now you should connect the board to the Mini2440. Be careful to do that before powering the board, I’m not sure hot plugging it would be a good thing =)

Then you have to load the mcp251x module.

In order to configure the can connection, you have to push your can network bitrate into the proc filesystem.

4 Comments

  1. Danila Danila

    Hallo,
    das sieht sehr interessant aus. Kannst du die Schaltung vergrößert reinstellen? Leider erkennt man nicht viel auf dem kleinen Bild

    Gruß,
    Daniel

    • cor cor

      Hi,
      indeed the images were quite small, by clicking on them you can have the full resolution now.

  2. Simon Simon

    Hi,

    I found a source for the 34way 2mm pitch connectors and interconnecting ribbon cables at Toby Electronics on-line! They also do the other sizes that are on the mini2440 board Smile

    Regards,
    Simon.

  3. Dave M. Dave M.

    Nice work on this but a couple of issues. You have no decoupling capacitors on your board. You should consider at least one 0.1uF ceramic at each devices power pins as close as you can get.
    Also consider a 4u7F cap near the power input on the header. You have a ribbon cable from your board and this is good practice to decouple it.
    You should consider beefing up the power tracks to 1mm width. The look a bit on the light side.

    Good luck with Eagle. I prefer Altium myself.
    Regards
    Dave…

Leave a Reply

Your email address will not be published. Required fields are marked *

Click to Insert Smiley

SmileBig SmileGrinLaughFrownBig FrownCryNeutralWinkKissRazzChicCoolAngryReally AngryConfusedQuestionThinkingPainShockYesNoLOLSillyBeautyLashesCuteShyBlushKissedIn LoveDroolGiggleSnickerHeh!SmirkWiltWeepIDKStruggleSide FrownDazedHypnotizedSweatEek!Roll EyesSarcasmDisdainSmugMoney MouthFoot in MouthShut MouthQuietShameBeat UpMeanEvil GrinGrit TeethShoutPissed OffReally PissedMad RazzDrunken RazzSickYawnSleepyDanceClapJumpHandshakeHigh FiveHug LeftHug RightKiss BlowKissingByeGo AwayCall MeOn the PhoneSecretMeetingWavingStopTime OutTalk to the HandLoserLyingDOH!Fingers CrossedWaitingSuspenseTremblePrayWorshipStarvingEatVictoryCurseAlienAngelClownCowboyCyclopsDevilDoctorFemale FighterMale FighterMohawkMusicNerdPartyPirateSkywalkerSnowmanSoldierVampireZombie KillerGhostSkeletonBunnyCatCat 2ChickChickenChicken 2CowCow 2DogDog 2DuckGoatHippoKoalaLionMonkeyMonkey 2MousePandaPigPig 2SheepSheep 2ReindeerSnailTigerTurtleBeerDrinkLiquorCoffeeCakePizzaWatermelonBowlPlateCanFemaleMaleHeartBroken HeartRoseDead RosePeaceYin YangUS FlagMoonStarSunCloudyRainThunderUmbrellaRainbowMusic NoteAirplaneCarIslandAnnouncebrbMailCellPhoneCameraFilmTVClockLampSearchCoinsComputerConsolePresentSoccerCloverPumpkinBombHammerKnifeHandcuffsPillPoopCigarette